Skip to content

Instantly share code, notes, and snippets.

@milessabin
Created April 5, 2014 13:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save milessabin/9991675 to your computer and use it in GitHub Desktop.
Save milessabin/9991675 to your computer and use it in GitHub Desktop.
shapeless's Typeable in action ...
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