Created
May 26, 2014 02:41
-
-
Save travisbrown/00fadaa6b51bf882ab92 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import scala.concurrent.{ ExecutionContext, Future } | |
import shapeless._, ops.tuple.{ IsComposite, LeftFolder, Prepend } | |
object zipAndAdd extends Poly2 { | |
implicit def only[B, A](implicit p: Prepend[B, Tuple1[A]], executor: ExecutionContext) = | |
at[Future[B], Future[A]] { | |
(fb, fa) => fb.zip(fa).map { case (b, a) => p(b, Tuple1(a)) } | |
} | |
} | |
def zipN[P, FH, H, T, O](p: P)(implicit | |
comp: IsComposite.Aux[P, FH, T], | |
ev: FH <:< Future[H], | |
folder: LeftFolder.Aux[T, Future[Tuple1[H]], zipAndAdd.type, O], | |
executor: ExecutionContext | |
): O = folder(comp.tail(p), comp.head(p).map(Tuple1(_))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And then:
In response to discussion of this Stack Overflow answer.