Specialized traverse and sequence methods for Traversable[Future[A]] => Future[Traversable[A]]
This commit is contained in:
parent
783fc85611
commit
a76e62096f
1 changed files with 7 additions and 0 deletions
|
|
@ -129,7 +129,14 @@ object Futures {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import scala.collection.mutable.Builder
|
||||||
|
import scala.collection.generic.CanBuildFrom
|
||||||
|
|
||||||
|
def sequence[A, M[_] <: Traversable[_]](in: M[Future[A]], timeout: Long = Actor.TIMEOUT)(implicit cbf: CanBuildFrom[M[Future[A]], A, M[A]]): Future[M[A]] =
|
||||||
|
in.foldLeft(new DefaultCompletableFuture[Builder[A, M[A]]](timeout).completeWithResult(cbf(in)): Future[Builder[A, M[A]]])((fb, fa) => for (a <- fa.asInstanceOf[Future[A]]; b <- fb) yield (b += a)).map(_.result)
|
||||||
|
|
||||||
|
def traverse[A, B, M[_] <: Traversable[_]](in: M[A], timeout: Long = Actor.TIMEOUT)(fn: A => Future[B])(implicit cbf: CanBuildFrom[M[A], B, M[B]]): Future[M[B]] =
|
||||||
|
in.foldLeft(new DefaultCompletableFuture[Builder[B, M[B]]](timeout).completeWithResult(cbf(in)): Future[Builder[B, M[B]]])((fb, fa) => for (a <- fn(fa.asInstanceOf[A]); b <- fb) yield (b += a)).map(_.result)
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed trait Future[T] {
|
sealed trait Future[T] {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue