Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.42 KB | None | 0 0
  1. object size extends Poly1 {
  2.   implicit def caseInt = at[Int](x => 1)
  3.   implicit def caseString = at[String](_.length)
  4.   implicit def caseTuple[T, U]
  5.     (implicit st : Case.Aux[T, Int], su : Case.Aux[U, Int]) =
  6.       at[(T, U)](t => size(t._1)+size(t._2))
  7. }
  8.  
  9. scala> size(23)
  10. res4: Int = 1
  11.  
  12. scala> size("foo")
  13. res5: Int = 3
  14.  
  15. scala> size((23, "foo"))
  16. res6: Int = 4
  17.  
  18. scala> size(((23, "foo"), 13))
  19. res7: Int = 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement