Search in sources :

Example 91 with ReactiveSeq

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

the class ReactiveStreamX method onEmptySwitch.

@Override
public ReactiveSeq<T> onEmptySwitch(final Supplier<? extends Stream<T>> switchTo) {
    final Object value = new Object();
    ReactiveSeq res = createSeq(onEmptyGet((Supplier) () -> value).flatMap(s -> {
        if (s == value)
            return (Stream) switchTo.get();
        return Stream.of(s);
    }));
    return res;
}
Also used : Tuple4(cyclops.data.tuple.Tuple4) Tuple3(cyclops.data.tuple.Tuple3) Connectable(com.oath.cyclops.types.stream.Connectable) Tuple2(cyclops.data.tuple.Tuple2) java.util(java.util) Continuation(com.oath.cyclops.types.futurestream.Continuation) PersistentCollection(com.oath.cyclops.types.persistent.PersistentCollection) QueueFactories(com.oath.cyclops.async.QueueFactories) Getter(lombok.Getter) Topic(com.oath.cyclops.async.adapters.Topic) Wither(lombok.experimental.Wither) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) com.oath.cyclops.internal.stream.spliterators.push(com.oath.cyclops.internal.stream.spliterators.push) Future(cyclops.control.Future) Vector(cyclops.data.Vector) Seq(cyclops.data.Seq) Tuple(cyclops.data.tuple.Tuple) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamSupport(java.util.stream.StreamSupport) Collector(java.util.stream.Collector) Subscriber(org.reactivestreams.Subscriber) cyclops.control(cyclops.control) Spouts(cyclops.reactive.Spouts) Zipping3Spliterator(com.oath.cyclops.internal.stream.spliterators.Zipping3Spliterator) Streams(cyclops.companion.Streams) Publisher(org.reactivestreams.Publisher) OneToOneConcurrentArrayQueue(org.agrona.concurrent.OneToOneConcurrentArrayQueue) Monoid(cyclops.function.Monoid) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) LockSupport(java.util.concurrent.locks.LockSupport) ReactiveSeq(cyclops.reactive.ReactiveSeq) Queue(com.oath.cyclops.async.adapters.Queue) Stream(java.util.stream.Stream) Function3(cyclops.function.Function3) Function4(cyclops.function.Function4) Subscription(org.reactivestreams.Subscription) IterableX(com.oath.cyclops.types.traversable.IterableX) SYNC(com.oath.cyclops.internal.stream.ReactiveStreamX.Type.SYNC) ExceptionSoftener(com.oath.cyclops.util.ExceptionSoftener) BACKPRESSURE(com.oath.cyclops.internal.stream.ReactiveStreamX.Type.BACKPRESSURE) QueueFactory(com.oath.cyclops.async.adapters.QueueFactory) java.util.function(java.util.function) Signal(com.oath.cyclops.async.adapters.Signal) AllArgsConstructor(lombok.AllArgsConstructor) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Stream(java.util.stream.Stream) ReactiveSeq(cyclops.reactive.ReactiveSeq)

Example 92 with ReactiveSeq

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

the class SpliteratorBasedStream method onEmptySwitch.

@Override
public ReactiveSeq<T> onEmptySwitch(final Supplier<? extends Stream<T>> switchTo) {
    final Object value = new Object();
    ReactiveSeq res = createSeq(onEmptyGet((Supplier) () -> value).flatMap(s -> {
        if (s == value)
            return (Stream) switchTo.get();
        return Stream.of(s);
    }));
    return res;
}
Also used : Tuple4(cyclops.data.tuple.Tuple4) Tuple3(cyclops.data.tuple.Tuple3) Tuple2(cyclops.data.tuple.Tuple2) java.util(java.util) Continuation(com.oath.cyclops.types.futurestream.Continuation) PersistentCollection(com.oath.cyclops.types.persistent.PersistentCollection) QueueFactories(com.oath.cyclops.async.QueueFactories) ValueEmittingSpliterator(com.oath.cyclops.internal.stream.spliterators.push.ValueEmittingSpliterator) LazyEither(cyclops.control.LazyEither) java.util.stream(java.util.stream) ValueSubscriber(com.oath.cyclops.types.reactive.ValueSubscriber) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CollectingSinkSpliterator(com.oath.cyclops.internal.stream.spliterators.push.CollectingSinkSpliterator) Vector(cyclops.data.Vector) Seq(cyclops.data.Seq) Eval(cyclops.control.Eval) Tuple(cyclops.data.tuple.Tuple) Comparator.comparing(java.util.Comparator.comparing) Subscriber(org.reactivestreams.Subscriber) cyclops.companion(cyclops.companion) Maybe(cyclops.control.Maybe) Spouts(cyclops.reactive.Spouts) OnErrorBreakOperator(com.oath.cyclops.internal.stream.spliterators.push.OnErrorBreakOperator) java.util.concurrent(java.util.concurrent) Publisher(org.reactivestreams.Publisher) PublisherIterable(com.oath.cyclops.internal.stream.publisher.PublisherIterable) ReactiveSeq(cyclops.reactive.ReactiveSeq) Function3(cyclops.function.Function3) Function4(cyclops.function.Function4) com.oath.cyclops.internal.stream.spliterators(com.oath.cyclops.internal.stream.spliterators) Subscription(org.reactivestreams.Subscription) java.util.function(java.util.function) Signal(com.oath.cyclops.async.adapters.Signal) ReactiveSeq(cyclops.reactive.ReactiveSeq)

Example 93 with ReactiveSeq

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

the class AsyncZippingTest 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) Test(org.junit.Test)

Example 94 with ReactiveSeq

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

the class ReactiveZippingTest 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) Test(org.junit.Test)

Example 95 with ReactiveSeq

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

the class ReactiveZippingTest method testUnzip4.

@Test
public void testUnzip4() {
    Supplier<ReactiveSeq<Tuple4<Integer, String, Long, Character>>> s = () -> of(new Tuple4(1, "a", 2l, 'z'), new Tuple4(2, "b", 3l, 'y'), new Tuple4(3, "c", 4l, 'x'));
    Tuple4<ReactiveSeq<Integer>, ReactiveSeq<String>, ReactiveSeq<Long>, ReactiveSeq<Character>> u1 = ReactiveSeq.unzip4(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)));
    assertTrue(u1._4().toList().containsAll(asList('z', 'y', 'x')));
}
Also used : Tuple4(cyclops.data.tuple.Tuple4) ReactiveSeq(cyclops.reactive.ReactiveSeq) 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