Search in sources :

Example 1 with AnyMSeq

use of com.oath.cyclops.anym.AnyMSeq in project cyclops by aol.

the class RxTest method anyMAsync.

@Test
public void anyMAsync() {
    AtomicBoolean complete = new AtomicBoolean(false);
    ReactiveSeq<Integer> asyncSeq = Spouts.async(Stream.of(1, 2, 3), Executors.newFixedThreadPool(1));
    Observable<Integer> observableAsync = Observables.observableFrom(asyncSeq);
    AnyMSeq<observable, Integer> monad = Observables.anyM(observableAsync);
    monad.map(i -> i * 2).forEach(System.out::println, System.err::println, () -> complete.set(true));
    System.out.println("Blocked? " + complete.get());
    while (!complete.get()) {
        Thread.yield();
    }
    Observable<Integer> converted = ObservableAnyM.raw(monad);
}
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) Rx2Witness.observable(cyclops.monads.Rx2Witness.observable) Test(org.junit.Test)

Example 2 with AnyMSeq

use of com.oath.cyclops.anym.AnyMSeq in project cyclops by aol.

the class AbstractAnyMSeqTest method testShuffleRandom.

@Test
public void testShuffleRandom() {
    Random r = new Random();
    Supplier<AnyMSeq<W, Integer>> s = () -> of(1, 2, 3);
    assertEquals(3, s.get().shuffle(r).to(ReactiveConvertableSequence::converter).listX().size());
    assertThat(s.get().shuffle(r).to(ReactiveConvertableSequence::converter).listX(), hasItems(1, 2, 3));
}
Also used : Random(java.util.Random) ReactiveConvertableSequence(com.oath.cyclops.ReactiveConvertableSequence) AnyMSeq(com.oath.cyclops.anym.AnyMSeq) Test(org.junit.Test)

Aggregations

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