Created
August 7, 2017 19:12
-
-
Save hamishdickson/a66d4933dd3938284b1751cf5af646cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats._ | |
import cats.data._ | |
import cats.implicits._ | |
import shapeless._ | |
object GeneralShow { | |
implicit val hnilShow = Show.show[HNil](_ => "") | |
implicit def hconsShow[H, T <: HList]( | |
implicit | |
hShow: Show[H], | |
tShow: Show[T] | |
): Show[H :: T] = new Show[H :: T] { | |
def show(ls: H :: T): String = ls.head.show + " " + ls.tail.show | |
} | |
implicit def autoShow[T, Repr]( | |
implicit | |
genericT: Generic.Aux[T, Repr], | |
genericShow: Lazy[Show[Repr]] | |
): Show[T] = new Show[T] { | |
def show(t: T): String = genericShow.value.show(genericT.to(t)) | |
} | |
} | |
object Test { | |
import GeneralShow._ | |
implicitly[Show[Int :: String :: HNil]] | |
case class Foo(i: Int, s: String) | |
case class Bar(f: Foo) | |
implicitly[Show[Bar]] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment