Search in sources :

Example 31 with FutureStream

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;
}
Also used : ListX(cyclops.reactive.collections.mutable.ListX) Blocker(com.oath.cyclops.react.collectors.lazy.Blocker) Tuple2(cyclops.data.tuple.Tuple2) java.util(java.util) ReactiveConvertableSequence(com.oath.cyclops.ReactiveConvertableSequence) LazyReact(cyclops.futurestream.LazyReact) FutureStream(cyclops.futurestream.FutureStream) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) Tuple(cyclops.data.tuple.Tuple) FilteredExecutionPathException(com.oath.cyclops.internal.react.exceptions.FilteredExecutionPathException) SimpleReactFailedStageException(com.oath.cyclops.react.SimpleReactFailedStageException) StreamSupport(java.util.stream.StreamSupport) Collector(java.util.stream.Collector) EagerStreamWrapper(com.oath.cyclops.internal.react.stream.EagerStreamWrapper) ThrowsSoftened(com.oath.cyclops.util.ThrowsSoftened) Continueable(com.oath.cyclops.react.async.subscription.Continueable) Streams(cyclops.companion.Streams) Executor(java.util.concurrent.Executor) Predicate(java.util.function.Predicate) CompletionException(java.util.concurrent.CompletionException) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) ReactiveSeq(cyclops.reactive.ReactiveSeq) StageWithResults(com.oath.cyclops.react.StageWithResults) Queue(com.oath.cyclops.async.adapters.Queue) Stream(java.util.stream.Stream) Status(com.oath.cyclops.react.Status) SimpleReact(cyclops.futurestream.SimpleReact) QueueFactory(com.oath.cyclops.async.adapters.QueueFactory) Tuple2(cyclops.data.tuple.Tuple2) ReactiveSeq(cyclops.reactive.ReactiveSeq)

Aggregations

FutureStream (cyclops.futurestream.FutureStream)31 Test (org.junit.Test)27 Tuple2 (cyclops.data.tuple.Tuple2)19 Stream (java.util.stream.Stream)17 BaseSeqTest (cyclops.futurestream.react.base.BaseSeqTest)16 LazyReact (cyclops.futurestream.LazyReact)12 Queue (com.oath.cyclops.async.adapters.Queue)11 ReactiveSeq (cyclops.reactive.ReactiveSeq)11 Collectors (java.util.stream.Collectors)11 QueueFactories (com.oath.cyclops.async.QueueFactories)8 Collection (java.util.Collection)8 Signal (com.oath.cyclops.async.adapters.Signal)7 ThreadPools (com.oath.cyclops.react.ThreadPools)7 Tuple.tuple (cyclops.data.tuple.Tuple.tuple)7 Serializable (java.io.Serializable)7 Arrays.asList (java.util.Arrays.asList)7 List (java.util.List)6 ForkJoinPool (java.util.concurrent.ForkJoinPool)6 Matchers.is (org.hamcrest.Matchers.is)6 Ignore (org.junit.Ignore)6