Created
April 5, 2014 13:01
-
-
Save milessabin/9991675 to your computer and use it in GitHub Desktop.
shapeless's Typeable in action ...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> import syntax.typeable._ | |
import syntax.typeable._ | |
scala> val wat: Any = List(1, 2, 3, 4) | |
wat: Any = List(1, 2, 3, 4) | |
scala> wat.cast[List[Int]].map(_.sum) | |
res0: Option[Int] = Some(10) | |
scala> val wat2: Any = "foo" | |
wat2: Any = foo | |
scala> wat2.cast[List[Int]].map(_.sum) | |
res1: Option[Int] = None | |
scala> val wat3: Any = List("foo", "bar", "baz") | |
wat3: Any = List(foo, bar, baz) | |
scala> wat3.cast[List[Int]].map(_.sum) | |
res2: Option[Int] = None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment