use of cyclops.futurestream.FutureStream in project cyclops by aol.
the class SimpleReactStream method zip.
/**
* Zip two Streams, zipping against the underlying futures of both Streams
* Placeholders (Futures) will be populated immediately in the new zipped Stream and results
* will be populated asyncrhonously
*
* @param other Another FutureStream to zip Futures with
* @return New Sequence of CompletableFutures
*/
default <R> SimpleReactStream<Tuple2<U, R>> zip(final SimpleReactStream<R> other) {
final ReactiveSeq seq = ReactiveSeq.fromStream(getLastActive().stream()).zip(ReactiveSeq.fromStream(other.getLastActive().stream()));
final ReactiveSeq<Tuple2<CompletableFuture<U>, CompletableFuture<R>>> withType = seq;
final SimpleReactStream futureStream = fromStreamOfFutures((Stream) withType.map(t -> CompletableFuture.allOf(t._1(), t._2()).thenApply(v -> Tuple.tuple(t._1().join(), t._2().join()))));
return futureStream;
}
Aggregations