Search in sources :

Example 31 with ReactiveSeq

use of cyclops.reactive.ReactiveSeq in project cyclops by aol.

the class AsyncRSZippingTest method testUnzip3.

@Test
public void testUnzip3() {
    Supplier<ReactiveSeq<Tuple3<Integer, String, Long>>> s = () -> of(new Tuple3(1, "a", 2l), new Tuple3(2, "b", 3l), new Tuple3(3, "c", 4l));
    Tuple3<ReactiveSeq<Integer>, ReactiveSeq<String>, ReactiveSeq<Long>> u1 = ReactiveSeq.unzip3(s.get());
    assertTrue(u1._1().toList().containsAll(Arrays.asList(1, 2, 3)));
    assertTrue(u1._2().toList().containsAll(asList("a", "b", "c")));
    assertTrue(u1._3().toList().containsAll(asList(2l, 3l, 4l)));
}
Also used : Tuple3(cyclops.data.tuple.Tuple3) ReactiveSeq(cyclops.reactive.ReactiveSeq) FluxReactiveSeq(cyclops.reactive.FluxReactiveSeq) Test(org.junit.Test)

Example 32 with ReactiveSeq

use of cyclops.reactive.ReactiveSeq in project cyclops by aol.

the class FluxesTest method asyncList.

@Test
public void asyncList() {
    AtomicBoolean complete = new AtomicBoolean(false);
    Flux<Integer> async = Flux.just(1, 2, 3).publishOn(Schedulers.single()).map(i -> {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
        }
        return i;
    }).doOnComplete(() -> complete.set(true));
    ListX<Integer> asyncList = ListX.listX(reactiveSeq(async)).map(i -> i + 1);
    System.out.println("Triggering list population!");
    asyncList.materialize();
    System.out.println("Were we blocked? Has the stream completed? " + complete.get());
    System.out.println("First value is " + asyncList.get(0));
    System.out.println("Completed? " + complete.get());
}
Also used : ListX(cyclops.reactive.collections.mutable.ListX) Tuple2(cyclops.data.tuple.Tuple2) Spouts(cyclops.reactive.Spouts) Fluxs(cyclops.companion.reactor.Fluxs) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Witness(cyclops.monads.Witness) AnyMs(cyclops.monads.AnyMs) Executors(java.util.concurrent.Executors) Assert.assertThat(org.junit.Assert.assertThat) ReactiveSeq(cyclops.reactive.ReactiveSeq) Flux(reactor.core.publisher.Flux) Tuple(cyclops.data.tuple.Tuple) Stream(java.util.stream.Stream) FluxAnyM(cyclops.monads.FluxAnyM) Witness.optional(cyclops.monads.Witness.optional) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Schedulers(reactor.core.scheduler.Schedulers) Optional(java.util.Optional) FluxReactiveSeq.reactiveSeq(cyclops.reactive.FluxReactiveSeq.reactiveSeq) AnyM(cyclops.monads.AnyM) StreamT(cyclops.monads.transformers.StreamT) FluxReactiveSeqImpl(com.oath.cyclops.reactor.adapter.FluxReactiveSeqImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 33 with ReactiveSeq

use of cyclops.reactive.ReactiveSeq in project cyclops by aol.

the class SyncZippingTest 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).toList().containsAll(Arrays.asList(1, 2)));
    assertTrue(u1._2().toList().containsAll(asList("a", "b", "c")));
}
Also used : Tuple2(cyclops.data.tuple.Tuple2) ReactiveSeq(cyclops.reactive.ReactiveSeq) FluxReactiveSeq(cyclops.reactive.FluxReactiveSeq) Test(org.junit.Test)

Example 34 with ReactiveSeq

use of cyclops.reactive.ReactiveSeq in project cyclops by aol.

the class SyncZippingTest method testUnzip3.

@Test
public void testUnzip3() {
    Supplier<ReactiveSeq<Tuple3<Integer, String, Long>>> s = () -> of(new Tuple3(1, "a", 2l), new Tuple3(2, "b", 3l), new Tuple3(3, "c", 4l));
    Tuple3<ReactiveSeq<Integer>, ReactiveSeq<String>, ReactiveSeq<Long>> u1 = ReactiveSeq.unzip3(s.get());
    assertTrue(u1._1().toList().containsAll(Arrays.asList(1, 2, 3)));
    assertTrue(u1._2().toList().containsAll(asList("a", "b", "c")));
    assertTrue(u1._3().toList().containsAll(asList(2l, 3l, 4l)));
}
Also used : Tuple3(cyclops.data.tuple.Tuple3) ReactiveSeq(cyclops.reactive.ReactiveSeq) FluxReactiveSeq(cyclops.reactive.FluxReactiveSeq) Test(org.junit.Test)

Example 35 with ReactiveSeq

use of cyclops.reactive.ReactiveSeq in project cyclops by aol.

the class SyncZippingTest method testUnzip3WithLimits.

@Test
public void testUnzip3WithLimits() {
    Supplier<ReactiveSeq<Tuple3<Integer, String, Long>>> s = () -> of(new Tuple3(1, "a", 2l), new Tuple3(2, "b", 3l), new Tuple3(3, "c", 4l));
    Tuple3<ReactiveSeq<Integer>, ReactiveSeq<String>, ReactiveSeq<Long>> u1 = ReactiveSeq.unzip3(s.get());
    assertTrue(u1._1().limit(1).toList().containsAll(Arrays.asList(1)));
    assertTrue(u1._2().limit(2).toList().containsAll(asList("a", "b")));
    assertTrue(u1._3().toList().containsAll(asList(2l, 3l, 4l)));
}
Also used : Tuple3(cyclops.data.tuple.Tuple3) ReactiveSeq(cyclops.reactive.ReactiveSeq) FluxReactiveSeq(cyclops.reactive.FluxReactiveSeq) Test(org.junit.Test)

Aggregations

ReactiveSeq (cyclops.reactive.ReactiveSeq)101 Test (org.junit.Test)91 Tuple3 (cyclops.data.tuple.Tuple3)33 Tuple4 (cyclops.data.tuple.Tuple4)33 Tuple2 (cyclops.data.tuple.Tuple2)31 FlowableReactiveSeq (cyclops.reactive.FlowableReactiveSeq)19 FluxReactiveSeq (cyclops.reactive.FluxReactiveSeq)18 Stream (java.util.stream.Stream)17 Collectors (java.util.stream.Collectors)16 FutureStream (cyclops.futurestream.FutureStream)12 QueueFactories (com.oath.cyclops.async.QueueFactories)11 Queue (com.oath.cyclops.async.adapters.Queue)11 LazyReact (cyclops.futurestream.LazyReact)11 Supplier (java.util.function.Supplier)10 Signal (com.oath.cyclops.async.adapters.Signal)9 List (java.util.List)9 Spouts (cyclops.reactive.Spouts)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 Matchers.equalTo (org.hamcrest.Matchers.equalTo)8 Assert.assertThat (org.junit.Assert.assertThat)8