Skip to content

Instantly share code, notes, and snippets.

@logicalguess
Last active September 11, 2017 02:49
Show Gist options
  • Select an option

  • Save logicalguess/a9575ea10fda571ff21e4e5dd74aa869 to your computer and use it in GitHub Desktop.

Select an option

Save logicalguess/a9575ea10fda571ff21e4e5dd74aa869 to your computer and use it in GitHub Desktop.
mapper from an HList to another
trait HListMapper[In <: HList, Out <: HList] {
def apply(in: In): Out
}
object HListMapper {
implicit def caseHNil: HListMapper[HNil, HNil] = (in: HNil) => HNil
implicit def caseHList[H1, H2, T1 <: HList, T2 <: HList]
(
implicit
headMapper: H1 => H2,
tailMapper: HListMapper[T1, T2]
): HListMapper[H1 :: T1, H2 :: T2] = (in: H1 :: T1) => headMapper(in.head) :: tailMapper(in.tail)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment