Skip to content

Instantly share code, notes, and snippets.

@andyscott
Last active December 21, 2015 20:29
Show Gist options
  • Save andyscott/6361691 to your computer and use it in GitHub Desktop.
Save andyscott/6361691 to your computer and use it in GitHub Desktop.
sequencing List[Future[A \/ B]]
type FutureEither[A, B] = EitherT[Future, A, B]
implicit class SequenceOverFutureEither[F[_], A, B](v: F[FutureEither[A, B]])(implicit F0: Traverse[F]) {
def sequenceR() = v.sequence[({ type λ[R] = FutureEither[A, R] })#λ, B]
}
@LeifWarner
Copy link

I don't see F0 used in the body there, so it seems you could also write that using "context bound" syntax, as F[_] : Traverse. And if you wanted to avoid that type lambda, you could specify it on a seperate line.
Together, that would give you something that looked like:

implicit class SequenceOverFutureEither[F[_] : Traverse, A, B](v: F[FutureEither[A, B]]) {
  type FutureEitherA[R] = FutureEither[A, R]
  def sequenceR() = v.sequence[FutureEitherA, B]
}

Maybe I should just get more used to those type lambdas, though... :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment