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.46 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. object Leaf {
  12.   implicit val show = Show[Node].contramap[Leaf](_.node)
  13. }
  14.  
  15. object InternalNode {
  16.   implicit val show = Show[Node].contramap[Leaf](_.node)
  17. }
  18.  
  19. println(Leaf("1488", Node("mynode")).show)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement