Skip to content

Instantly share code, notes, and snippets.

@Softsapiens
Forked from milessabin/gist:9991675
Created April 6, 2014 18:25
Show Gist options
  • Save Softsapiens/10009771 to your computer and use it in GitHub Desktop.
Save Softsapiens/10009771 to your computer and use it in GitHub Desktop.
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