Created
June 20, 2012 02:42
-
-
Save milessabin/2957866 to your computer and use it in GitHub Desktop.
Map over a List of hlist'able things, yield a List of their first elements
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 shapeless._ | |
import shapeless._ | |
scala> import Tuples._ | |
import Tuples._ | |
scala> def fst[P <: Product, H, T <: HList](p : P)(implicit hl : HListerAux[P, H :: T]) = hl(p).head | |
fst: [P <: Product, H, T <: shapeless.HList](p: P)(implicit hl: shapeless.HListerAux[P,shapeless.::[H,T]])H | |
scala> val l = List(("foo", "bar"), ("baz", "wibble")) | |
l: List[(String, String)] = List((foo,bar), (baz,wibble)) | |
scala> for(x <- l) yield fst(x) // l map fst interacts badly with type inference ... must do better! | |
res0: List[String] = List(foo, baz) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment