use of cyclops.reactive.ReactiveSeq in project cyclops by aol.
the class MiscTest method pVectorX.
@Test
public void pVectorX() {
ReactiveSeq<String> seq = Spouts.from(VectorX.of(1, 2, 3, 4).plus(5).map(i -> "connect toNested Akka, RxJava and more with reactiveBuffer-streams" + i));
PersistentSetX<String> setX = seq.to(s -> new LazyReact().fromStream(s)).map(data -> "fan out across threads with futureStreams" + data).to(ReactiveConvertableSequence::converter).persistentSetX();
}
use of cyclops.reactive.ReactiveSeq in project cyclops by aol.
the class SimpleReactStream method zipWithIndex.
/**
* Zip this Stream with an index, but Zip based on the underlying tasks, not completed results.
*
* e.g.
* two function that return method name, but take varying lengths of time.
* <pre>
* <code>
* EagerFutureStream.react(()->takesALotOfTime(),()->veryQuick()).zipWithIndex();
*
* [["takesALotOfTime",0],["veryQuick",1]]
*
* Where as with standard zipWithIndex you would getValue a new Stream ordered by completion
*
* [["veryQuick",0],["takesALotOfTime",1]]
* </code>
* </pre>
*/
default SimpleReactStream<Tuple2<U, Long>> zipWithIndex() {
final ReactiveSeq seq = ReactiveSeq.fromIterator(getLastActive().stream().iterator()).zipWithIndex();
final ReactiveSeq<Tuple2<CompletableFuture<U>, Long>> withType = seq;
final SimpleReactStream futureStream = fromStreamOfFutures((Stream) withType.map(t -> t._1().thenApply(v -> Tuple.tuple(t._1().join(), t._2()))));
return futureStream;
}
use of cyclops.reactive.ReactiveSeq 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;
}
use of cyclops.reactive.ReactiveSeq in project cyclops by aol.
the class SimpleReactStream method splitAt.
/**
* Split a stream at a given position. (Operates on futures)
* <pre>
* {@code
* // tuple((1, 2, 3), (4, 5, 6))
* EagerFutureStream.of(1, 2, 3, 4, 5,6).splitAt(3)
*
* }</pre>
* @return
*/
default Tuple2<SimpleReactStream<U>, SimpleReactStream<U>> splitAt(final int position) {
final Stream stream = getLastActive().stream();
final Tuple2<ReactiveSeq<CompletableFuture<U>>, ReactiveSeq<CompletableFuture<U>>> split = ReactiveSeq.fromStream((Stream<CompletableFuture<U>>) stream).splitAt(position);
return Tuple.tuple(fromListCompletableFuture(split._1().collect(Collectors.toList())), fromListCompletableFuture(split._2().collect(Collectors.toList())));
}
use of cyclops.reactive.ReactiveSeq in project cyclops by aol.
the class LazySeqAgronaTest method shouldZipFiniteWithInfiniteSeq.
@Test
public void shouldZipFiniteWithInfiniteSeq() throws Exception {
ThreadPools.setUseCommon(false);
final ReactiveSeq<Integer> units = new LazyReact(ThreadPools.getCommonFreeThread()).iterate(1, n -> n + 1).limit(5);
// <-- MEMORY LEAK! - no auto-closing yet, so writes infinetely to it's async queue
final FutureStream<Integer> hundreds = new LazyReact(ThreadPools.getCommonFreeThread()).iterate(100, n -> n + 100);
final ReactiveSeq<String> zipped = units.zip(hundreds, (n, p) -> n + ": " + p);
assertThat(zipped.limit(5).join(), equalTo(of("1: 100", "2: 200", "3: 300", "4: 400", "5: 500").join()));
ThreadPools.setUseCommon(true);
}
Aggregations