Search in sources :

Example 16 with Tuple2

use of cyclops.data.tuple.Tuple2 in project cyclops by aol.

the class LazySeqObjectPoolingTest method testZipWithFuturesCoreStream.

@Test
public void testZipWithFuturesCoreStream() {
    Stream stream = Stream.of("a", "b");
    FutureStream<Tuple2<Integer, String>> seq = of(1, 2).actOnFutures().zip(stream);
    // .map(tuple -> Tuple.tuple(tuple.v1.join(),tuple.v2)).collect(CyclopsCollectors.toList());
    List<Tuple2<Integer, String>> result = seq.block();
    assertThat(result.size(), is(asList(tuple(1, "a"), tuple(2, "b")).size()));
}
Also used : Tuple2(cyclops.data.tuple.Tuple2) FutureStream(cyclops.futurestream.FutureStream) Stream(java.util.stream.Stream) BaseSeqTest(cyclops.futurestream.react.base.BaseSeqTest) Test(org.junit.Test)

Example 17 with Tuple2

use of cyclops.data.tuple.Tuple2 in project cyclops by aol.

the class LazySeqObjectPoolingTest method testZipWithFuturesStream.

@Test
public void testZipWithFuturesStream() {
    Stream stream = of("a", "b");
    FutureStream<Tuple2<Integer, String>> seq = of(1, 2).actOnFutures().zip(stream);
    // .map(tuple -> Tuple.tuple(tuple.v1.join(),tuple.v2)).collect(CyclopsCollectors.toList());
    List<Tuple2<Integer, String>> result = seq.block();
    assertThat(result.size(), is(asList(tuple(1, "a"), tuple(2, "b")).size()));
}
Also used : Tuple2(cyclops.data.tuple.Tuple2) FutureStream(cyclops.futurestream.FutureStream) Stream(java.util.stream.Stream) BaseSeqTest(cyclops.futurestream.react.base.BaseSeqTest) Test(org.junit.Test)

Example 18 with Tuple2

use of cyclops.data.tuple.Tuple2 in project cyclops by aol.

the class LazySequentialSeqAgronaTest method testZipWithFutures.

@Test
public void testZipWithFutures() {
    Stream stream = of("a", "b");
    List<Tuple2<Integer, String>> result = of(1, 2).actOnFutures().zip(stream).block();
    assertThat(result, is(asList(tuple(1, "a"), tuple(2, "b"))));
}
Also used : Tuple2(cyclops.data.tuple.Tuple2) FutureStream(cyclops.futurestream.FutureStream) Stream(java.util.stream.Stream) Test(org.junit.Test) BaseSequentialSeqTest(cyclops.futurestream.react.base.BaseSequentialSeqTest)

Example 19 with Tuple2

use of cyclops.data.tuple.Tuple2 in project cyclops by aol.

the class SpoutsZipTest method pairWise.

@Test
public void pairWise() {
    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);
    Spouts.of(1).zip(Spouts.of("test")).zip(Spouts.of("test2")).map(t -> Tuple.tuple(t._1()._1(), t._1()._2() + t._2())).forEach(n -> {
        data.set(true);
        values.updateAndGet(v -> v.plus(n));
    }, e -> {
        error.set(e);
    }, () -> {
        complete.set(true);
    });
    assertTrue(data.get());
    assertTrue(complete.get());
    assertNull(error.get());
    assertThat(values.get(), equalTo(Vector.of(Tuple.tuple(1, "testtest2"))));
}
Also used : Tuple4(cyclops.data.tuple.Tuple4) Tuple3(cyclops.data.tuple.Tuple3) Tuple2(cyclops.data.tuple.Tuple2) Arrays(java.util.Arrays) Matchers.isOneOf(org.hamcrest.Matchers.isOneOf) StepVerifier(reactor.test.StepVerifier) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Vector(cyclops.data.Vector) AtomicReference(java.util.concurrent.atomic.AtomicReference) Seq(cyclops.data.Seq) Tuple(cyclops.data.tuple.Tuple) Matchers.contains(org.hamcrest.Matchers.contains) Subscription(org.reactivestreams.Subscription) EmitterProcessor(reactor.core.publisher.EmitterProcessor) Matchers.equalTo(org.hamcrest.Matchers.equalTo) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assert(org.junit.Assert) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Vector(cyclops.data.Vector) Test(org.junit.Test)

Example 20 with Tuple2

use of cyclops.data.tuple.Tuple2 in project cyclops by aol.

the class BaseSequentialTest 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());
    assertThat(u1._1().toList(), equalTo(asList(1, 2, 3)));
    assertThat(u1._2().toList(), equalTo(asList("a", "b", "c")));
}
Also used : Tuple2(cyclops.data.tuple.Tuple2) ReactiveSeq(cyclops.reactive.ReactiveSeq) Test(org.junit.Test)

Aggregations

Tuple2 (cyclops.data.tuple.Tuple2)43 Test (org.junit.Test)35 ReactiveSeq (cyclops.reactive.ReactiveSeq)23 Stream (java.util.stream.Stream)17 FutureStream (cyclops.futurestream.FutureStream)16 Tuple (cyclops.data.tuple.Tuple)10 BaseSeqTest (cyclops.futurestream.react.base.BaseSeqTest)9 Collectors (java.util.stream.Collectors)7 FlowableReactiveSeq (cyclops.reactive.FlowableReactiveSeq)6 FluxReactiveSeq (cyclops.reactive.FluxReactiveSeq)6 java.util (java.util)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Queue (com.oath.cyclops.async.adapters.Queue)5 Vector (cyclops.data.Vector)5 Tuple3 (cyclops.data.tuple.Tuple3)5 LazyReact (cyclops.futurestream.LazyReact)5 Streams (cyclops.companion.Streams)4 Executor (java.util.concurrent.Executor)4 Function (java.util.function.Function)4