Sitelet https://github.com/typelevel/cats/commit/31bbd26e771d69350d7e8911d97a4a8b5be49aa5
Skip to content

Commit 31bbd26

Browse files
committed
Use helper constructor for Show instances
1 parent 0905398 commit 31bbd26

18 files changed

Lines changed: 32 additions & 85 deletions

File tree

‎core/src/main/scala-2.12/cats/instances/stream.scala‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,7 @@ trait StreamInstances extends cats.kernel.instances.StreamInstances {
194194
}
195195

196196
implicit def catsStdShowForStream[A: Show]: Show[Stream[A]] =
197-
new Show[Stream[A]] {
198-
def show(fa: Stream[A]): String = if (fa.isEmpty) "Stream()" else s"Stream(${fa.head.show}, ?)"
199-
}
197+
Show.show(stream => if (stream.isEmpty) "Stream()" else s"Stream(${stream.head.show}, ?)")
200198

201199
implicit def catsStdParallelForStreamZipStream: Parallel.Aux[Stream, ZipStream] =
202200
new Parallel[Stream] {

‎core/src/main/scala-2.13+/cats/instances/lazyList.scala‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ trait LazyListInstances extends cats.kernel.instances.LazyListInstances {
176176
}
177177

178178
implicit def catsStdShowForLazyList[A: Show]: Show[LazyList[A]] =
179-
new Show[LazyList[A]] {
180-
def show(fa: LazyList[A]): String = if (fa.isEmpty) "LazyList()" else s"LazyList(${fa.head.show}, ?)"
181-
}
179+
Show.show(list => if (list.isEmpty) "LazyList()" else s"LazyList(${list.head.show}, ?)")
182180

183181
implicit val catsStdTraverseFilterForLazyList: TraverseFilter[LazyList] = new TraverseFilter[LazyList] {
184182
val traverse: Traverse[LazyList] = catsStdInstancesForLazyList

‎core/src/main/scala-2.13+/cats/instances/stream.scala‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,7 @@ trait StreamInstances extends cats.kernel.instances.StreamInstances {
196196

197197
@deprecated("Use cats.instances.lazyList", "2.0.0-RC2")
198198
implicit def catsStdShowForStream[A: Show]: Show[Stream[A]] =
199-
new Show[Stream[A]] {
200-
def show(fa: Stream[A]): String = if (fa.isEmpty) "Stream()" else s"Stream(${fa.head.show}, ?)"
201-
}
199+
Show.show(stream => if (stream.isEmpty) "Stream()" else s"Stream(${stream.head.show}, ?)")
202200

203201
@deprecated("Use catsStdParallelForZipLazyList", "2.0.0-RC2")
204202
implicit def catsStdParallelForStreamZipStream: Parallel.Aux[Stream, ZipStream] =

‎core/src/main/scala/cats/data/Const.scala‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ sealed abstract private[data] class ConstInstances extends ConstInstances0 {
104104
}
105105

106106
implicit def catsDataShowForConst[A: Show, B]: Show[Const[A, B]] =
107-
new Show[Const[A, B]] {
108-
def show(f: Const[A, B]): String = f.show
109-
}
107+
Show.show(_.show)
110108

111109
implicit def catsDataTraverseForConst[C]: Traverse[Const[C, *]] =
112110
new Traverse[Const[C, *]] {

‎core/src/main/scala/cats/data/Ior.scala‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,9 +864,7 @@ sealed abstract private[data] class IorInstances extends IorInstances0 {
864864
}
865865

866866
implicit def catsDataShowForIor[A: Show, B: Show]: Show[A Ior B] =
867-
new Show[A Ior B] {
868-
def show(f: A Ior B): String = f.show
869-
}
867+
Show.show(_.show)
870868

871869
implicit def catsDataSemigroupForIor[A: Semigroup, B: Semigroup]: Semigroup[Ior[A, B]] =
872870
new Semigroup[Ior[A, B]] {

‎core/src/main/scala/cats/data/Validated.scala‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -928,9 +928,7 @@ sealed abstract private[data] class ValidatedInstances extends ValidatedInstance
928928
}
929929

930930
implicit def catsDataShowForValidated[A, B](implicit A: Show[A], B: Show[B]): Show[Validated[A, B]] =
931-
new Show[Validated[A, B]] {
932-
def show(f: Validated[A, B]): String = f.show
933-
}
931+
Show.show(_.show)
934932

935933
implicit val catsDataBitraverseForValidated: Bitraverse[Validated] =
936934
new Bitraverse[Validated] {

‎core/src/main/scala/cats/data/WriterT.scala‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,7 @@ sealed abstract private[data] class WriterTInstances2 extends WriterTInstances3
449449
}
450450

451451
implicit def catsDataShowForWriterT[F[_], L, V](implicit F: Show[F[(L, V)]]): Show[WriterT[F, L, V]] =
452-
new Show[WriterT[F, L, V]] {
453-
override def show(f: WriterT[F, L, V]): String = f.show
454-
}
452+
Show.show(_.show)
455453

456454
implicit def catsDataMonoidForWriterTId[L: Monoid, V: Monoid]: Monoid[WriterT[Id, L, V]] =
457455
catsDataMonoidForWriterT[Id, L, V]

‎core/src/main/scala/cats/instances/either.scala‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,9 @@ trait EitherInstances extends cats.kernel.instances.EitherInstances {
232232
}
233233

234234
implicit def catsStdShowForEither[A, B](implicit A: Show[A], B: Show[B]): Show[Either[A, B]] =
235-
new Show[Either[A, B]] {
236-
def show(x: Either[A, B]): String =
237-
x match {
238-
case Left(a) => "Left(" + A.show(a) + ")"
239-
case Right(b) => "Right(" + B.show(b) + ")"
240-
}
235+
Show.show {
236+
case Left(a) => "Left(" + A.show(a) + ")"
237+
case Right(b) => "Right(" + B.show(b) + ")"
241238
}
242239

243240
implicit def catsParallelForEitherAndValidated[E: Semigroup]: Parallel.Aux[Either[E, *], Validated[E, *]] =

‎core/src/main/scala/cats/instances/list.scala‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,14 @@
2222
package cats
2323
package instances
2424

25-
import cats.data.{Chain, ZipList}
25+
import cats.data.{Chain, Ior, ZipList}
2626
import cats.instances.StaticMethods.appendAll
2727
import cats.kernel.compat.scalaVersionSpecific._
2828
import cats.kernel.instances.StaticMethods.wrapMutableIndexedSeq
29-
import cats.syntax.show._
3029

3130
import scala.annotation.tailrec
3231
import scala.collection.mutable.ListBuffer
3332

34-
import cats.data.Ior
35-
3633
trait ListInstances extends cats.kernel.instances.ListInstances {
3734

3835
implicit val catsStdInstancesForList
@@ -278,10 +275,7 @@ trait ListInstances extends cats.kernel.instances.ListInstances {
278275
}
279276

280277
implicit def catsStdShowForList[A: Show]: Show[List[A]] =
281-
new Show[List[A]] {
282-
def show(fa: List[A]): String =
283-
fa.iterator.map(_.show).mkString("List(", ", ", ")")
284-
}
278+
Show.show(_.iterator.map(Show[A].show).mkString("List(", ", ", ")"))
285279

286280
implicit def catsStdNonEmptyParallelForListZipList: NonEmptyParallel.Aux[List, ZipList] =
287281
new NonEmptyParallel[List] {

‎core/src/main/scala/cats/instances/map.scala‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ import cats.data.Ior
3232
trait MapInstances extends cats.kernel.instances.MapInstances {
3333

3434
implicit def catsStdShowForMap[A, B](implicit showA: Show[A], showB: Show[B]): Show[Map[A, B]] =
35-
new Show[Map[A, B]] {
36-
def show(m: Map[A, B]): String =
37-
m.iterator
38-
.map { case (a, b) => showA.show(a) + " -> " + showB.show(b) }
39-
.mkString("Map(", ", ", ")")
40-
}
35+
Show.show(
36+
_.iterator
37+
.map { case (a, b) => showA.show(a) + " -> " + showB.show(b) }
38+
.mkString("Map(", ", ", ")")
39+
)
4140

4241
implicit def catsStdInstancesForMap[K]: UnorderedTraverse[Map[K, *]] with FlatMap[Map[K, *]] with Align[Map[K, *]] =
4342
new UnorderedTraverse[Map[K, *]] with FlatMap[Map[K, *]] with Align[Map[K, *]] {

0 commit comments

Comments
 (0)