Skip to content

Instantly share code, notes, and snippets.

@gszeliga
Last active May 11, 2016 16:20
Show Gist options
  • Save gszeliga/73a0c5c120bbfa70ad3931d5cc431317 to your computer and use it in GitHub Desktop.
Save gszeliga/73a0c5c120bbfa70ad3931d5cc431317 to your computer and use it in GitHub Desktop.
public static <T> CompletableFuture<Stream<T>> sequence(Stream<CompletableFuture<T>> source) {
return source
.reduce(completedFuture(Stream.empty()),
(fl, fo) -> fl.thenCombine(fo, (s, o) -> concat(s, Stream.of(o))),
(fa, fb) -> fa.thenCombine(fb, Stream::concat));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment