Created
October 10, 2015 11:32
-
-
Save tomaszperek/4aecc9839d766b43a051 to your computer and use it in GitHub Desktop.
IsHListOfFutures 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 IsHListOfFutures { | |
def apply[In <: HList, Out <: HList](implicit isHzippable: IsHListOfFutures[In, Out]): IsHListOfFutures[In, Out] = isHzippable | |
implicit object HNilIsListOfFutures extends IsHListOfFutures[HNil, HNil] { | |
override def hsequence(l : HNil)(implicit ec: ExecutionContext): Future[HNil] = Future.successful(HNil) | |
} | |
implicit def hconsIsHListOfFutures[H, In <: HList, Out <: HList] | |
(implicit ev: IsHListOfFutures[In, Out]): IsHListOfFutures[Future[H] :: In, H :: Out] = new IsHListOfFutures[Future[H] :: In, H :: Out] { | |
override def hsequence(l : Future[H] :: In)(implicit ec: ExecutionContext): Future[H :: Out] = { | |
val head = l.head | |
val tail = l.tail | |
head.flatMap(h => ev.hsequence(tail).map(h :: _)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment