Created
August 13, 2013 18:49
-
-
Save timperrett/6224373 to your computer and use it in GitHub Desktop.
Shapeless typed element selection
This file contains hidden or 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
Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_25). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> import shapeless._, HList._ | |
import shapeless._ | |
import HList._ | |
scala> "foo" :: 124 :: HNil | |
res0: shapeless.::[java.lang.String,shapeless.::[Int,shapeless.HNil]] = foo :: 124 :: HNil | |
scala> res0.select[Int] | |
res1: Int = 124 | |
scala> res0.select[String] | |
res2: String = foo | |
scala> List(1,2,3) :: List("sdf","sdfs") :: HNil | |
res3: shapeless.::[List[Int],shapeless.::[List[java.lang.String],shapeless.HNil]] = List(1, 2, 3) :: List(sdf, sdfs) :: HNil | |
scala> res3.select[List[String]] | |
res4: List[String] = List(sdf, sdfs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment