All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aol.cyclops.rx.adapter.ObservableReactiveSeq Maven / Gradle / Ivy

There is a newer version: 9.0.0-MI7
Show newest version
package com.aol.cyclops.rx.adapter;

import com.aol.cyclops2.internal.stream.ReactiveStreamX;
import com.aol.cyclops2.internal.stream.StreamX;
import com.aol.cyclops2.types.anyM.AnyMSeq;
import com.aol.cyclops2.types.stream.HeadAndTail;
import com.aol.cyclops2.types.traversable.Traversable;
import cyclops.async.adapters.QueueFactory;
import cyclops.collections.immutable.VectorX;
import cyclops.collections.mutable.ListX;
import cyclops.companion.rx.Observables;
import cyclops.control.Maybe;
import cyclops.control.lazy.Either;
import cyclops.function.Monoid;
import cyclops.function.Reducer;
import cyclops.monads.AnyM;
import cyclops.monads.Witness;
import cyclops.monads.Witness.reactiveSeq;
import cyclops.monads.Witness.stream;
import cyclops.monads.transformers.ListT;
import cyclops.stream.ReactiveSeq;
import cyclops.stream.Spouts;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.experimental.Wither;
import org.jooq.lambda.tuple.Tuple;
import org.jooq.lambda.tuple.Tuple2;
import org.jooq.lambda.tuple.Tuple3;
import org.jooq.lambda.tuple.Tuple4;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import rx.Observable;


import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.*;
import java.util.stream.*;


@AllArgsConstructor
public class ObservableReactiveSeq implements ReactiveSeq {
    @Wither
    @Getter
    Observable observable;

    public  ObservableReactiveSeq observable(Observable observable){
        return new ObservableReactiveSeq<>(observable);
    }
    public  ObservableReactiveSeq observable(ReactiveSeq observable){
        if(observable instanceof ObservableReactiveSeq){
            return  (ObservableReactiveSeq)observable;
        }
        return new ObservableReactiveSeq<>(Observables.observableFrom(observable));
    }

    @Override
    public  ReactiveSeq coflatMap(Function, ? extends R> fn) {
        return observable(Observable.just(fn.apply(this)));
    }

    @Override
    public  ReactiveSeq unit(T1 unit) {
        return observable(Observable.just(unit));
    }

    @Override
    public  U foldRight(U identity, BiFunction accumulator) {
        return observable.reduce(identity,(a,b)->accumulator.apply(b,a))
                         .toBlocking()
                         .first();
    }

    @Override
    public  ReactiveSeq zipS(Stream other, BiFunction zipper) {
         if(other instanceof ReactiveSeq){
            ReactiveSeq o = (ReactiveSeq)other;
            return o.visit(sync->observable(observable.zipWith(ReactiveSeq.fromStream((Stream)other),(a,b)->zipper.apply(a,b))),
                    rs->observable(observable.zipWith(ReactiveSeq.fromStream((Stream)other),(a,b)->zipper.apply(a,b))),
                    async->observable(observable.zipWith(ReactiveSeq.fromStream((Stream)other),(a,b)->zipper.apply(a,b))));

        }
        if(other instanceof Publisher){
            return zipP((Publisher)other,zipper);
        }

        return observable(observable.zipWith(ReactiveSeq.fromStream((Stream)other),(a,b)->zipper.apply(a,b)));
    }

    @Override
    public  ReactiveSeq zipLatest(Publisher other, BiFunction zipper) {
        Observable obs = Observable.combineLatest(observable, Observables.observable(other), (a, b) -> zipper.apply((T)a, (U)b));
        return observable(obs);
    }

    @Override
    public  ReactiveSeq zipP(Publisher other, BiFunction zipper) {
        return observable(observable.zipWith(Observables.observable(other),(a,b)->zipper.apply(a,b)));
    }

    @Override
    public  ReactiveSeq> zipP(Publisher other) {
        return observable(observable.zipWith(Observables.observable(other),Tuple::tuple));
    }

    @Override
    public ReactiveSeq cycle() {
        return observable(observable.repeat());
    }

    @Override
    public Tuple2, ReactiveSeq> duplicate() {
        return Observables.connectToReactiveSeq(observable).duplicate().map((s1, s2)->Tuple.tuple(observable(s1),observable(s2)));
    }

    @Override
    public Tuple2, ReactiveSeq> duplicate(Supplier> bufferFactory) {
        return Observables.connectToReactiveSeq(observable).duplicate(bufferFactory).map((s1, s2)->Tuple.tuple(observable(s1),observable(s2)));
    }

    @Override
    public Tuple3, ReactiveSeq, ReactiveSeq> triplicate() {
        return Observables.connectToReactiveSeq(observable).triplicate().map((s1, s2, s3)->Tuple.tuple(observable(s1),observable(s2),observable(s3)));
    }

    @Override
    public Tuple3, ReactiveSeq, ReactiveSeq> triplicate(Supplier> bufferFactory) {
        return Observables.connectToReactiveSeq(observable).triplicate(bufferFactory).map((s1, s2, s3)->Tuple.tuple(observable(s1),observable(s2),observable(s3)));
    }

    @Override
    public Tuple4, ReactiveSeq, ReactiveSeq, ReactiveSeq> quadruplicate() {
        return Observables.connectToReactiveSeq(observable).quadruplicate().map((s1, s2, s3, s4)->Tuple.tuple(observable(s1),observable(s2),observable(s3),observable(s4)));
    }

    @Override
    public Tuple4, ReactiveSeq, ReactiveSeq, ReactiveSeq> quadruplicate(Supplier> bufferFactory) {
        return Observables.connectToReactiveSeq(observable).quadruplicate(bufferFactory).map((s1, s2, s3, s4)->Tuple.tuple(observable(s1),observable(s2),observable(s3),observable(s4)));
    }

    @Override
    public Tuple2, ReactiveSeq> splitAtHead() {
        return Observables.connectToReactiveSeq(observable).splitAtHead().map((s1, s2)->Tuple.tuple(s1,observable(s2)));
    }

    @Override
    public Tuple2, ReactiveSeq> splitAt(int where) {
        return Observables.connectToReactiveSeq(observable).splitAt(where).map((s1, s2)->Tuple.tuple(observable(s1),observable(s2)));
    }

    @Override
    public Tuple2, ReactiveSeq> splitBy(Predicate splitter) {
        return Observables.connectToReactiveSeq(observable).splitBy(splitter).map((s1, s2)->Tuple.tuple(observable(s1),observable(s2)));
    }

    @Override
    public Tuple2, ReactiveSeq> partition(Predicate splitter) {
        return Observables.connectToReactiveSeq(observable).partition(splitter).map((s1, s2)->Tuple.tuple(observable(s1),observable(s2)));
    }

    @Override
    public  ReactiveSeq> zipS(Stream other) {

        return zipS(other,Tuple::tuple);
    }

    @Override
    public  ReactiveSeq> zip3(Iterable second, Iterable third) {
        return zip(second,Tuple::tuple).zip(third,(a,b)->Tuple.tuple(a.v1,a.v2,b));
    }

    @Override
    public  ReactiveSeq> zip4(Iterable second, Iterable third, Iterable fourth) {
        return zip(second,Tuple::tuple).zip(third,(a,b)->Tuple.tuple(a.v1,a.v2,b))
                .zip(fourth,(a,b)->(Tuple4)Tuple.tuple(a.v1,a.v2,a.v3,b));
    }

    @Override
    public ReactiveSeq> sliding(int windowSize, int increment) {
        return observable(Observables.connectToReactiveSeq(observable).sliding(windowSize,increment));
    }

    @Override
    public ReactiveSeq> grouped(int groupSize) {
        return observable(observable.buffer(groupSize).map(ListX::fromIterable));
    }

    @Override
    public ReactiveSeq> groupedStatefullyUntil(BiPredicate, ? super T> predicate) {
        return observable(Observables.connectToReactiveSeq(observable).groupedStatefullyUntil(predicate));
    }

    @Override
    public , R> ReactiveSeq groupedStatefullyUntil(BiPredicate predicate, Supplier factory, Function finalizer) {
        return observable(Observables.connectToReactiveSeq(observable).groupedStatefullyUntil(predicate,factory,finalizer));
    }

    @Override
    public ReactiveSeq> groupedStatefullyWhile(BiPredicate, ? super T> predicate) {
        return observable(Observables.connectToReactiveSeq(observable).groupedStatefullyWhile(predicate));
    }

    @Override
    public , R> ReactiveSeq groupedStatefullyWhile(BiPredicate predicate, Supplier factory, Function finalizer) {
        return observable(Observables.connectToReactiveSeq(observable).groupedStatefullyWhile(predicate,factory,finalizer));
    }

    @Override
    public ReactiveSeq> groupedBySizeAndTime(int size, long time, TimeUnit t) {
        return observable(Observables.connectToReactiveSeq(observable).groupedBySizeAndTime(size, time, t));
    }

    @Override
    public > ReactiveSeq groupedBySizeAndTime(int size, long time, TimeUnit unit, Supplier factory) {
        return observable(Observables.connectToReactiveSeq(observable).groupedBySizeAndTime(size,time,unit,factory));
    }

    @Override
    public , R> ReactiveSeq groupedBySizeAndTime(int size, long time, TimeUnit unit, Supplier factory, Function finalizer) {
        return observable(Observables.connectToReactiveSeq(observable).groupedBySizeAndTime(size,time,unit,factory,finalizer));
    }

    @Override
    public , R> ReactiveSeq groupedByTime(long time, TimeUnit unit, Supplier factory, Function finalizer) {
        return groupedBySizeAndTime(Integer.MAX_VALUE,time,unit,factory,finalizer);
    }

    @Override
    public ReactiveSeq> groupedByTime(long time, TimeUnit t) {
        return observable(Observables.connectToReactiveSeq(observable).groupedByTime(time, t));
    }

    @Override
    public > ReactiveSeq groupedByTime(long time, TimeUnit unit, Supplier factory) {
        return observable(Observables.connectToReactiveSeq(observable).groupedByTime(time, unit, factory));
    }

    @Override
    public > ReactiveSeq grouped(int size, Supplier supplier) {
        return observable(Observables.connectToReactiveSeq(observable).grouped(size,supplier));
    }

    @Override
    public ReactiveSeq> groupedWhile(Predicate predicate) {
        return observable(Observables.connectToReactiveSeq(observable).groupedWhile(predicate));
    }

    @Override
    public > ReactiveSeq groupedWhile(Predicate predicate, Supplier factory) {
        return observable(Observables.connectToReactiveSeq(observable).groupedWhile(predicate,factory));
    }

    @Override
    public ReactiveSeq distinct() {
        return observable(observable.distinct());
    }

    @Override
    public  ReactiveSeq scanLeft(U seed, BiFunction function) {
        return observable(observable.scan(seed,(a,b)->function.apply(a,b)));
    }

    @Override
    public ReactiveSeq sorted() {
        return observable(Observables.connectToReactiveSeq(observable).sorted());
    }

    @Override
    public ReactiveSeq skip(long num) {
        return observable(observable.skip((int)num));
    }


    @Override
    public void forEach(Consumer action) {
        Observables.connectToReactiveSeq(observable).forEach(action);
    }

    @Override
    public void forEachOrdered(Consumer action) {
        Observables.connectToReactiveSeq(observable).forEachOrdered(action);
    }

    @Override
    public Object[] toArray() {
        return Observables.connectToReactiveSeq(observable).toArray();
    }

    @Override
    public  A[] toArray(IntFunction generator) {
        return Observables.connectToReactiveSeq(observable).toArray(generator);
    }

    @Override
    public ReactiveSeq skipWhile(Predicate p) {
        return observable(observable.skipWhile(t->p.test(t)));
    }

    @Override
    public ReactiveSeq limit(long num) {
        return observable(observable.take((int)num));
    }

    @Override
    public ReactiveSeq limitWhile(Predicate p) {
        return observable(Observables.connectToReactiveSeq(observable).takeWhile(p));
    }
    @Override
    public ReactiveSeq limitWhileClosed(Predicate p) {
        return observable(observable.takeWhile(t->p.test(t)));
    }

    @Override
    public ReactiveSeq limitUntil(Predicate p) {
       return observable(Observables.connectToReactiveSeq(observable).limitUntil(p));
    }

    @Override
    public ReactiveSeq limitUntilClosed(Predicate p) {
        return observable(observable.takeUntil(t->p.test(t)));
    }

    @Override
    public ReactiveSeq parallel() {
        return this;
    }

    @Override
    public boolean allMatch(Predicate c) {
        return Observables.connectToReactiveSeq(observable).allMatch(c);
    }

    @Override
    public boolean anyMatch(Predicate c) {
        return Observables.connectToReactiveSeq(observable).anyMatch(c);
    }

    @Override
    public boolean xMatch(int num, Predicate c) {
        return Observables.connectToReactiveSeq(observable).xMatch(num,c);
    }

    @Override
    public boolean noneMatch(Predicate c) {
        return Observables.connectToReactiveSeq(observable).noneMatch(c);
    }

    @Override
    public String join() {
        return Observables.connectToReactiveSeq(observable).join();
    }

    @Override
    public String join(String sep) {
        return Observables.connectToReactiveSeq(observable).join(sep);
    }

    @Override
    public String join(String sep, String start, String end) {
        return Observables.connectToReactiveSeq(observable).join(sep,start,end);
    }

    @Override
    public HeadAndTail headAndTail() {
        return Observables.connectToReactiveSeq(observable).headAndTail();
    }

    @Override
    public Optional findFirst() {
        return Observables.connectToReactiveSeq(observable).findFirst();
    }

    @Override
    public Maybe findOne() {
        return Observables.connectToReactiveSeq(observable).findOne();
    }

    @Override
    public Either findFirstOrError() {
        return Observables.connectToReactiveSeq(observable).findFirstOrError();
    }

    @Override
    public Optional findAny() {
        return Observables.connectToReactiveSeq(observable).findAny();
    }

    @Override
    public  R mapReduce(Reducer reducer) {
        return Observables.connectToReactiveSeq(observable).mapReduce(reducer);
    }

    @Override
    public  R mapReduce(Function mapper, Monoid reducer) {
        return Observables.connectToReactiveSeq(observable).mapReduce(mapper,reducer);
    }

    @Override
    public T reduce(Monoid reducer) {
        return Observables.connectToReactiveSeq(observable).reduce(reducer);
    }

    @Override
    public Optional reduce(BinaryOperator accumulator) {
        return Observables.connectToReactiveSeq(observable).reduce(accumulator);
    }

    @Override
    public T reduce(T identity, BinaryOperator accumulator) {
        return Observables.connectToReactiveSeq(observable).reduce(identity,accumulator);
    }

    @Override
    public  U reduce(U identity, BiFunction accumulator, BinaryOperator combiner) {
        return Observables.connectToReactiveSeq(observable).reduce(identity, accumulator, combiner);
    }

    @Override
    public ListX reduce(Stream> reducers) {
        return Observables.connectToReactiveSeq(observable).reduce(reducers);
    }

    @Override
    public ListX reduce(Iterable> reducers) {
        return Observables.connectToReactiveSeq(observable).reduce(reducers);
    }

    @Override
    public T foldRight(Monoid reducer) {
        return Observables.connectToReactiveSeq(observable).foldRight(reducer);
    }

    @Override
    public T foldRight(T identity, BinaryOperator accumulator) {
        return Observables.connectToReactiveSeq(observable).foldRight(identity,accumulator);
    }

    @Override
    public  T1 foldRightMapToType(Reducer reducer) {
        return Observables.connectToReactiveSeq(observable).foldRightMapToType(reducer);
    }

    @Override
    public ReactiveSeq stream() {
        return Observables.connectToReactiveSeq(observable);
    }

    @Override
    public  Traversable unitIterator(Iterator U) {
        return new ObservableReactiveSeq<>(Observable.from(()->U));
    }

    @Override
    public boolean startsWithIterable(Iterable iterable) {
        return Observables.connectToReactiveSeq(observable).startsWithIterable(iterable);
    }

    @Override
    public boolean startsWith(Stream stream) {
        return Observables.connectToReactiveSeq(observable).startsWith(stream);
    }

    @Override
    public AnyMSeq anyM() {
        return AnyM.fromStream(this);
    }

    @Override
    public  ReactiveSeq map(Function fn) {
        return observable(observable.map(e->fn.apply(e)));
    }

    @Override
    public  ReactiveSeq flatMap(Function> fn) {
        return observable(observable.flatMap(s->Observables.fromStream(fn.apply(s))));
    }

    @Override
    public IntStream flatMapToInt(Function mapper) {
        return Observables.connectToReactiveSeq(observable).flatMapToInt(mapper);
    }

    @Override
    public LongStream flatMapToLong(Function mapper) {
        return Observables.connectToReactiveSeq(observable).flatMapToLong(mapper);
    }

    @Override
    public DoubleStream flatMapToDouble(Function mapper) {
        return Observables.connectToReactiveSeq(observable).flatMapToDouble(mapper);
    }

    @Override
    public  ReactiveSeq flatMapAnyM(Function> fn) {
        return observable(observable.flatMap(a->Observables.observable(fn.apply(a))));
    }

    @Override
    public  ReactiveSeq flatMapI(Function> fn) {
        return observable(observable.flatMapIterable(a->fn.apply(a)));
    }

    @Override
    public  ReactiveSeq flatMapP(Function> fn) {
        return observable(Observable.merge(observable.map(a->Observables.observable(fn.apply(a)))));
    }

    @Override
    public  ReactiveSeq flatMapP(int maxConcurrency, Function> fn) {
        return observable(Observable.merge(observable.map(a->Observables.observable(fn.apply(a))),maxConcurrency));
    }

    @Override
    public  ReactiveSeq flatMapStream(Function> fn) {
        
        return this.observable((Observable)observable.flatMap(a->fn.andThen(s->{
            ReactiveSeq res = s instanceof ReactiveSeq ? (ReactiveSeq) s : (ReactiveSeq) ReactiveSeq.fromSpliterator(s.spliterator());
           return Observables.fromStream(res);
                }
            
        ).apply(a)));
    }

    @Override
    public ReactiveSeq filter(Predicate fn) {
        return observable(observable.filter(t->fn.test(t)));
    }

    @Override
    public Iterator iterator() {
        return Observables.connectToReactiveSeq(observable).iterator();
    }

    @Override
    public Spliterator spliterator() {
        return Observables.connectToReactiveSeq(observable).spliterator();
    }

    @Override
    public boolean isParallel() {
        return false;
    }

    @Override
    public ReactiveSeq sequential() {
        return this;
    }

    @Override
    public ReactiveSeq unordered() {
        return this;
    }

    @Override
    public ReactiveSeq reverse() {
        return observable(Observables.connectToReactiveSeq(observable).reverse());
    }

    @Override
    public ReactiveSeq onClose(Runnable closeHandler) {
        return observable(observable.doOnCompleted(()->closeHandler.run()));
    }

    @Override
    public void close() {
        
    }

    @Override
    public ReactiveSeq prependS(Stream stream) {
        return observable(Observables.connectToReactiveSeq(observable).prependS(stream));
    }

    @Override
    public ReactiveSeq append(T... values) {
        return observable(Observables.connectToReactiveSeq(observable).append(values));
    }

    @Override
    public ReactiveSeq append(T value) {
        return observable(Observables.connectToReactiveSeq(observable).append(value));
    }

    @Override
    public ReactiveSeq prepend(T value) {
        return observable(Observables.connectToReactiveSeq(observable).prepend(value));
    }

    @Override
    public ReactiveSeq prepend(T... values) {
        return observable(Observables.connectToReactiveSeq(observable).prepend(values));
    }

    @Override
    public boolean endsWithIterable(Iterable iterable) {
        return Observables.connectToReactiveSeq(observable).endsWithIterable(iterable);
    }

    @Override
    public boolean endsWith(Stream stream) {
        return Observables.connectToReactiveSeq(observable).endsWith(stream);
    }

    @Override
    public ReactiveSeq skip(long time, TimeUnit unit) {
        return observable(observable.skip(time,unit));
    }

    @Override
    public ReactiveSeq limit(long time, TimeUnit unit) {
        return observable(observable.take(time,unit));
    }

    @Override
    public ReactiveSeq skipLast(int num) {
        return observable(observable.skipLast(num));
    }

    @Override
    public ReactiveSeq limitLast(int num) {
        return observable(observable.takeLast(num));
    }

    @Override
    public T firstValue() {
        return observable.toBlocking().first();
    }

    @Override
    public ReactiveSeq onEmptySwitch(Supplier> switchTo) {
        return observable(Observables.connectToReactiveSeq(observable).onEmptySwitch(switchTo));
    }

    @Override
    public ReactiveSeq onEmptyGet(Supplier supplier) {
        return observable(Observables.connectToReactiveSeq(observable).onEmptyGet(supplier));
    }

    @Override
    public  ReactiveSeq onEmptyThrow(Supplier supplier) {
        return observable(Observables.connectToReactiveSeq(observable).onEmptyThrow(supplier));
    }

    @Override
    public  ReactiveSeq distinct(Function keyExtractor) {
        return observable(observable.distinct(a->keyExtractor.apply(a)));
    }

    @Override
    public ReactiveSeq xPer(int x, long time, TimeUnit t) {
        return observable(Observables.connectToReactiveSeq(observable).xPer(x,time,t));
    }

    @Override
    public ReactiveSeq onePer(long time, TimeUnit t) {
        return observable(Observables.connectToReactiveSeq(observable).onePer(time,t));
    }

    @Override
    public ReactiveSeq debounce(long time, TimeUnit t) {
        return observable(Observables.connectToReactiveSeq(observable).debounce(time,t));
    }

    @Override
    public ReactiveSeq fixedDelay(long l, TimeUnit unit) {
        return observable(Observables.connectToReactiveSeq(observable).fixedDelay(l,unit));
    }

    @Override
    public ReactiveSeq jitter(long maxJitterPeriodInNanos) {
        return observable(Observables.connectToReactiveSeq(observable).jitter(maxJitterPeriodInNanos));
    }

    @Override
    public ReactiveSeq recover(Function fn) {
        return observable(Observables.connectToReactiveSeq(observable).recover(fn));
    }

    @Override
    public  ReactiveSeq recover(Class exceptionClass, Function fn) {
        return observable(Observables.connectToReactiveSeq(observable).recover(exceptionClass,fn));
    }

    @Override
    public long count() {
        return Observables.connectToReactiveSeq(observable).count();
    }

    @Override
    public ReactiveSeq appendS(Stream other) {
        return observable(Observables.connectToReactiveSeq(observable).appendS(other));
    }

    @Override
    public ReactiveSeq append(Iterable other) {
        return  observable(Observables.connectToReactiveSeq(observable).append(other));
    }

    @Override
    public ReactiveSeq prepend(Iterable other) {
        return observable(Observables.connectToReactiveSeq(observable).prepend(other));
    }

    @Override
    public ReactiveSeq cycle(long times) {
        return observable(observable.repeat(times));
    }

    @Override
    public ReactiveSeq skipWhileClosed(Predicate predicate) {
        return observable(Observables.connectToReactiveSeq(observable).skipWhileClosed(predicate));
    }


    @Override
    public String format() {
        return Observables.connectToReactiveSeq(observable).format();
    }

    @Override
    public ReactiveSeq changes() {
        return observable(Observables.connectToReactiveSeq(observable).changes());
    }



    @Override
    public  Subscription forEachSubscribe(Consumer consumer) {
        return Observables.connectToReactiveSeq(observable).forEachSubscribe(consumer);
    }

    @Override
    public  Subscription forEachSubscribe(Consumer consumer, Consumer consumerError) {
        return Observables.connectToReactiveSeq(observable).forEachSubscribe(consumer, consumerError);
    }

    @Override
    public  Subscription forEachSubscribe(Consumer consumer, Consumer consumerError, Runnable onComplete) {
        return Observables.connectToReactiveSeq(observable).forEachSubscribe(consumer, consumerError,onComplete);
    }

    @Override
    public  R collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner) {

        return Observables.connectToReactiveSeq(observable).collect(supplier,accumulator,combiner);
    }

    @Override
    public  ReactiveSeq collectStream(Collector collector) {
        return observable(Observables.connectToReactiveSeq(observable).collectStream(collector));
    }

    @Override
    public  R collect(Collector collector) {
        return Observables.connectToReactiveSeq(observable).collect((Collector)collector);
    }
    

    @Override
    public T singleUnsafe() {
        return single().get();
    }

    @Override
    public Maybe single(Predicate predicate) {
        return filter(predicate).single();
    }

    @Override
    public Maybe single() {
        return Observables.connectToReactiveSeq(observable).single();
    }

    @Override
    public ListX> multicast(int num) {
        return Observables.connectToReactiveSeq(observable).multicast(num).map(s->observable(s));
    }

    @Override
    public void subscribe(Subscriber s) {
        Observables.publisher(observable).subscribe(s);
    }
    @Override
    public  R visit(Function,? extends R> sync,Function,? extends R> reactiveStreams,
                       Function,? extends R> asyncNoBackPressure){
        return asyncNoBackPressure.apply(this);
    }
    @Override
    public ListT groupedT(int groupSize) {
        return ListT.fromStream(grouped(groupSize));
    }

    @Override
    public ListT slidingT(int windowSize, int increment) {
        return ListT.fromStream(sliding(windowSize,increment));
    }

    @Override
    public ListT slidingT(int windowSize) {
        return ListT.fromStream(sliding(windowSize));
    }

    @Override
    public ListT groupedUntilT(Predicate predicate) {
        return ListT.fromStream(groupedUntil(predicate));
    }

    @Override
    public ListT groupedStatefullyUntilT(BiPredicate, ? super T> predicate) {
        return ListT.fromStream(groupedStatefullyWhile(predicate));
    }

    @Override
    public ListT groupedWhileT(Predicate predicate) {
        return ListT.fromStream(groupedWhile(predicate));
    }
}