Search in sources :

Example 1 with Streams

use of cyclops.companion.Streams in project cyclops by aol.

the class SimpleReactStream method zip.

/**
 * Zip two Streams, zipping against the underlying futures of this stream
 *
 * @param other
 * @return
 */
default <R> SimpleReactStream<Tuple2<U, R>> zip(final Stream<R> other) {
    final ReactiveSeq seq = ReactiveSeq.fromStream(getLastActive().stream()).zip(ReactiveSeq.fromStream(other));
    final ReactiveSeq<Tuple2<CompletableFuture<U>, R>> withType = seq;
    final SimpleReactStream futureStream = fromStreamOfFutures((Stream) withType.map(t -> t._1().thenApply(v -> Tuple.tuple(t._1().join(), t._2()))));
    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)

Example 2 with Streams

use of cyclops.companion.Streams 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

ReactiveConvertableSequence (com.oath.cyclops.ReactiveConvertableSequence)2 Queue (com.oath.cyclops.async.adapters.Queue)2 QueueFactory (com.oath.cyclops.async.adapters.QueueFactory)2 FilteredExecutionPathException (com.oath.cyclops.internal.react.exceptions.FilteredExecutionPathException)2 EagerStreamWrapper (com.oath.cyclops.internal.react.stream.EagerStreamWrapper)2 SimpleReactFailedStageException (com.oath.cyclops.react.SimpleReactFailedStageException)2 StageWithResults (com.oath.cyclops.react.StageWithResults)2 Status (com.oath.cyclops.react.Status)2 Continueable (com.oath.cyclops.react.async.subscription.Continueable)2 Blocker (com.oath.cyclops.react.collectors.lazy.Blocker)2 ThrowsSoftened (com.oath.cyclops.util.ThrowsSoftened)2 Streams (cyclops.companion.Streams)2 Tuple (cyclops.data.tuple.Tuple)2 Tuple2 (cyclops.data.tuple.Tuple2)2 FutureStream (cyclops.futurestream.FutureStream)2 LazyReact (cyclops.futurestream.LazyReact)2 SimpleReact (cyclops.futurestream.SimpleReact)2 ReactiveSeq (cyclops.reactive.ReactiveSeq)2 ListX (cyclops.reactive.collections.mutable.ListX)2 java.util (java.util)2