Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case class Node(name: String)
- case class Leaf(value: String, node: Node)
- case class InternalNode(children: List[Node], node: Node)
- object Node {
- implicit val show = new Show[Node] {
- override def show(node: Node): String = s"(${node.name.show})"
- }
- }
- def derieve[F[_] : Contravariant, A, B](f: B => A)(implicit fa: F[A]): F[B] =
- Contravariant[F].contramap(fa)(f)
- object Leaf {
- implicit val show = derieve[Show, Node, Leaf](_.node)
- }
- object InternalNode {
- implicit val show = derieve[Show, Node, InternalNode](_.node)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement