Advertisement
Guest User

Untitled

a guest
Sep 6th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.44 KB | None | 0 0
  1. scala> def matchTypes(a: Any): String = a match {
  2.      |   case n: String => s"$n is a string"
  3.      |   case n: Int => s"$n is an integer"
  4.      |   case n: Boolean => s"$n is a boolean"
  5.      |   case _ => "some other type"
  6.      | }
  7. matchTypes: (a: Any)String
  8.  
  9. scala> matchTypes("hello")
  10. res0: String = hello is a string
  11.  
  12. scala> matchTypes(124)
  13. res1: String = 124 is an integer
  14.  
  15. scala> matchTypes(true)
  16. res2: String = true is a boolean
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement