Advertisement
Guest User

Untitled

a guest
Nov 26th, 2017
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.54 KB | None | 0 0
  1. case class Node(name: String)
  2. case class Leaf(value: String, node: Node)
  3. case class InternalNode(children: List[Node], node: Node)
  4.  
  5. object Node {
  6.   implicit val show = new Show[Node] {
  7.     override def show(node: Node): String = s"(${node.name.show})"
  8.   }
  9. }
  10.  
  11. def derieve[F[_] : Contravariant, A, B](f: B => A)(implicit fa: F[A]): F[B] =
  12.   Contravariant[F].contramap(fa)(f)
  13.  
  14. object Leaf {
  15.   implicit val show = derieve[Show, Node, Leaf](_.node)
  16. }
  17.  
  18. object InternalNode {
  19.   implicit val show = derieve[Show, Node, InternalNode](_.node)
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement