Skip to content

Instantly share code, notes, and snippets.

@milessabin
Created June 20, 2012 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milessabin/2957866 to your computer and use it in GitHub Desktop.
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
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