diff --git a/core/src/main/scala/cats/Show.scala b/core/src/main/scala/cats/Show.scala index dba5f4f4e0..e903274b1c 100644 --- a/core/src/main/scala/cats/Show.scala +++ b/core/src/main/scala/cats/Show.scala @@ -25,6 +25,7 @@ import java.util.UUID import scala.collection.immutable.{BitSet, Queue, Seq, SortedMap, SortedSet} import scala.concurrent.duration.{Duration, FiniteDuration} import scala.util.Try +import scala.{specialized => sp} /** * A type class to provide textual representation. It is meant to be a @@ -65,6 +66,13 @@ object Show extends ScalaVersionSpecificShowInstances with ShowInstances { */ def show[A](f: A => String): Show[A] = f(_) + /** + * Convert an implicit `Show[B]` to a `Show[A]` using the given + * function `f`. + */ + def by[@sp A, @sp B](f: A => B)(implicit ev: Show[B]): Show[A] = + a => ev.show(f(a)) + /** * creates an instance of [[Show]] using object toString */