Search in sources :

Example 1 with ListX

use of cyclops.reactive.collections.mutable.ListX in project cyclops by aol.

the class LazyListXTest method testIntercalate2.

@Test
public void testIntercalate2() {
    ListX needle = ListX.of(-1, -1, -1);
    ListX listOfLists = ListX.of(new ListX[] { ListX.of(1l, 2l, 3l), ListX.of(4l, 5l, 6l), ListX.of(7l, 8l, 9l) });
    ListX intercalated = needle.intercalate(listOfLists);
    assertThat(intercalated.size(), equalTo(15));
    assertThat(intercalated.get(0), equalTo(1l));
    assertThat(intercalated.get(1), equalTo(2l));
    assertThat(intercalated.get(2), equalTo(3l));
    assertThat(intercalated.get(3), equalTo(-1));
    assertThat(intercalated.get(4), equalTo(-1));
    assertThat(intercalated.get(5), equalTo(-1));
    assertThat(intercalated.get(6), equalTo(4l));
    assertThat(intercalated.get(7), equalTo(5l));
    assertThat(intercalated.get(8), equalTo(6l));
    assertThat(intercalated.get(9), equalTo(-1));
    assertThat(intercalated.get(10), equalTo(-1));
    assertThat(intercalated.get(11), equalTo(-1));
    assertThat(intercalated.get(12), equalTo(7l));
    assertThat(intercalated.get(13), equalTo(8l));
    assertThat(intercalated.get(14), equalTo(9l));
}
Also used : ListX(cyclops.reactive.collections.mutable.ListX) LazyListX(com.oath.cyclops.data.collections.extensions.lazy.LazyListX) Test(org.junit.Test)

Example 2 with ListX

use of cyclops.reactive.collections.mutable.ListX in project cyclops by aol.

the class RxTest method asyncFlowableList2.

@Test
public void asyncFlowableList2() {
    AtomicBoolean complete = new AtomicBoolean(false);
    Flowable<Integer> async = Flowable.fromPublisher(Spouts.reactive(Stream.of(100, 200, 300), Executors.newFixedThreadPool(1))).map(i -> {
        Thread.sleep(100);
        return i;
    }).doOnComplete(() -> complete.set(true));
    System.out.println("Initializing!");
    ListX<Integer> asyncList = FlowableCollections.listX(async).map(i -> i + 1);
    System.out.println("Blocked? " + complete.get());
    System.out.println("First value is " + asyncList.get(0));
    System.out.println("Blocked? " + complete.get());
}
Also used : ListX(cyclops.reactive.collections.mutable.ListX) Observables(cyclops.companion.rx2.Observables) ObservableAnyM(cyclops.monads.ObservableAnyM) ReactiveConvertableSequence(com.oath.cyclops.ReactiveConvertableSequence) FlowableReactiveSeq(cyclops.reactive.FlowableReactiveSeq) Spouts(cyclops.reactive.Spouts) AnyMSeq(com.oath.cyclops.anym.AnyMSeq) Flowables(cyclops.companion.rx2.Flowables) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) FlowableCollections(cyclops.reactive.FlowableCollections) Executors(java.util.concurrent.Executors) Assert.assertThat(org.junit.Assert.assertThat) ReactiveSeq(cyclops.reactive.ReactiveSeq) Stream(java.util.stream.Stream) ObservableReactiveSeq.reactiveSeq(cyclops.reactive.ObservableReactiveSeq.reactiveSeq) Rx2Witness.observable(cyclops.monads.Rx2Witness.observable) Flowable(io.reactivex.Flowable) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Observable(io.reactivex.Observable) ObservableReactiveSeq(cyclops.reactive.ObservableReactiveSeq) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 3 with ListX

use of cyclops.reactive.collections.mutable.ListX in project cyclops by aol.

the class RxTest method asyncFlowableList.

@Test
public void asyncFlowableList() {
    AtomicBoolean complete = new AtomicBoolean(false);
    Flowable<Integer> async = Flowable.fromPublisher(Spouts.reactive(Stream.of(100, 200, 300), Executors.newFixedThreadPool(1))).map(i -> {
        Thread.sleep(5000);
        return i;
    }).doOnComplete(() -> complete.set(true));
    ListX<Integer> asyncList = ListX.listX(FlowableReactiveSeq.reactiveSeq(async)).map(i -> i + 1);
    System.out.println("Calling materialize!");
    asyncList.materialize();
    System.out.println("Blocked? " + complete.get());
    System.out.println("First value is " + asyncList.get(0));
    System.out.println("Blocked? " + complete.get());
}
Also used : ListX(cyclops.reactive.collections.mutable.ListX) Observables(cyclops.companion.rx2.Observables) ObservableAnyM(cyclops.monads.ObservableAnyM) ReactiveConvertableSequence(com.oath.cyclops.ReactiveConvertableSequence) FlowableReactiveSeq(cyclops.reactive.FlowableReactiveSeq) Spouts(cyclops.reactive.Spouts) AnyMSeq(com.oath.cyclops.anym.AnyMSeq) Flowables(cyclops.companion.rx2.Flowables) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) FlowableCollections(cyclops.reactive.FlowableCollections) Executors(java.util.concurrent.Executors) Assert.assertThat(org.junit.Assert.assertThat) ReactiveSeq(cyclops.reactive.ReactiveSeq) Stream(java.util.stream.Stream) ObservableReactiveSeq.reactiveSeq(cyclops.reactive.ObservableReactiveSeq.reactiveSeq) Rx2Witness.observable(cyclops.monads.Rx2Witness.observable) Flowable(io.reactivex.Flowable) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Observable(io.reactivex.Observable) ObservableReactiveSeq(cyclops.reactive.ObservableReactiveSeq) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 4 with ListX

use of cyclops.reactive.collections.mutable.ListX 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)

Aggregations

ListX (cyclops.reactive.collections.mutable.ListX)4 Test (org.junit.Test)4 ReactiveSeq (cyclops.reactive.ReactiveSeq)3 Spouts (cyclops.reactive.Spouts)3 Executors (java.util.concurrent.Executors)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Stream (java.util.stream.Stream)3 Matchers.equalTo (org.hamcrest.Matchers.equalTo)3 Assert.assertThat (org.junit.Assert.assertThat)3 ReactiveConvertableSequence (com.oath.cyclops.ReactiveConvertableSequence)2 AnyMSeq (com.oath.cyclops.anym.AnyMSeq)2 Flowables (cyclops.companion.rx2.Flowables)2 Observables (cyclops.companion.rx2.Observables)2 ObservableAnyM (cyclops.monads.ObservableAnyM)2 Rx2Witness.observable (cyclops.monads.Rx2Witness.observable)2 FlowableCollections (cyclops.reactive.FlowableCollections)2 FlowableReactiveSeq (cyclops.reactive.FlowableReactiveSeq)2 ObservableReactiveSeq (cyclops.reactive.ObservableReactiveSeq)2 ObservableReactiveSeq.reactiveSeq (cyclops.reactive.ObservableReactiveSeq.reactiveSeq)2 Flowable (io.reactivex.Flowable)2