use of cyclops.data.tuple.Tuple2 in project cyclops by aol.
the class AbstractIterableXTest method pairWiseZipIncremental.
@Test
public void pairWiseZipIncremental() {
AtomicBoolean data = new AtomicBoolean(false);
AtomicReference<Vector<Tuple2<Integer, String>>> values = new AtomicReference<>(Vector.empty());
AtomicBoolean complete = new AtomicBoolean(false);
AtomicReference<Throwable> error = new AtomicReference<Throwable>(null);
Subscription sub = of(1).zip(of("test")).zip(of("test2")).map(t -> Tuple.tuple(t._1()._1(), t._1()._2() + t._2())).forEach(0, n -> {
data.set(true);
values.updateAndGet(v -> v.plus(n));
}, e -> {
error.set(e);
}, () -> {
complete.set(true);
});
assertFalse(data.get());
assertFalse(complete.get());
assertNull(error.get());
assertThat(values.get(), Matchers.equalTo(Vector.empty()));
sub.request(10l);
assertTrue(data.get());
assertTrue(complete.get());
assertNull(error.get());
assertThat(values.get(), Matchers.equalTo(Vector.of(Tuple.tuple(1, "testtest2"))));
}
use of cyclops.data.tuple.Tuple2 in project cyclops by aol.
the class ReactiveZippingRSTest method testUnzipWithLimits.
@Test
public void testUnzipWithLimits() {
Supplier<ReactiveSeq<Tuple2<Integer, String>>> s = () -> of(new Tuple2(1, "a"), new Tuple2(2, "b"), new Tuple2(3, "c"));
Tuple2<ReactiveSeq<Integer>, ReactiveSeq<String>> u1 = ReactiveSeq.unzip(s.get());
assertTrue(u1._1().limit(2).to(Streamable::fromStream).toList().containsAll(Arrays.asList(1, 2)));
assertTrue(u1._2().toList().containsAll(asList("a", "b", "c")));
}
use of cyclops.data.tuple.Tuple2 in project cyclops by aol.
the class ReactiveZippingRSTest method testUnzip.
@Test
public void testUnzip() {
Supplier<ReactiveSeq<Tuple2<Integer, String>>> s = () -> of(new Tuple2(1, "a"), new Tuple2(2, "b"), new Tuple2(3, "c"));
Tuple2<ReactiveSeq<Integer>, ReactiveSeq<String>> u1 = ReactiveSeq.unzip(s.get());
assertTrue(u1._1().toList().containsAll(Arrays.asList(1, 2, 3)));
assertTrue(u1._2().toList().containsAll(asList("a", "b", "c")));
}
use of cyclops.data.tuple.Tuple2 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.data.tuple.Tuple2 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;
}
Aggregations