Created
October 19, 2015 21:45
-
-
Save tomaszperek/4765f33adae56250c5e1 to your computer and use it in GitHub Desktop.
Implementation of IsHListOfM object
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
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