Skip to content

Instantly share code, notes, and snippets.

@milessabin
Created May 23, 2013 17:43
Show Gist options
  • Save milessabin/5637928 to your computer and use it in GitHub Desktop.
Save milessabin/5637928 to your computer and use it in GitHub Desktop.
Mapping get over an HList of Maps.
import shapeless._
trait Name
case class VarName(nme: String) extends Name
case class ParamName(nme: String) extends Name
def lookup(nme: String): Option[Name] :: Option[Name] :: HNil = {
object get extends Poly1 {
implicit def default[T <: Name] = at[Map[String, T]](_.get(nme))
}
val finalMap = Map("foo" -> VarName("foo")) :: Map("bar" -> ParamName("bar")) :: HNil
finalMap.map(get)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment