Skip to content

Instantly share code, notes, and snippets.

@tomaszperek
Created October 19, 2015 21:45
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 tomaszperek/4765f33adae56250c5e1 to your computer and use it in GitHub Desktop.
Save tomaszperek/4765f33adae56250c5e1 to your computer and use it in GitHub Desktop.
Implementation of IsHListOfM object
object IsHListOfM {
def apply[M[_], In <: HList, Out <: HList](implicit isHM: IsHListOfM[M, In, Out], m: Monad[M]): IsHListOfM[M, In, Out] = isHM
implicit def IsHNilHListOfM[M[_]](implicit m: Monad[M]) = new IsHListOfM[M, HNil, HNil] {
override def hsequence(l: HNil): M[HNil] = m.pure(HNil)
}
implicit def hconsIsHListOfM[M[_], H, In <: HList, Out <: HList](implicit ev: IsHListOfM[M, In, Out], m: Monad[M]): IsHListOfM[M, M[H] :: In, H :: Out] = new IsHListOfM[M, M[H] :: In, H :: Out] {
override def hsequence(l: M[H] :: In): M[H :: Out] =
l.head.flatMap(h => ev.hsequence(l.tail).map(h :: _))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment