cyclops.streams.RxOperators Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cyclops-rx Show documentation
Show all versions of cyclops-rx Show documentation
Converters and Comprehenders for RxJava
package cyclops.streams;
import cyclops.companion.rx.Observables;
import cyclops.stream.ReactiveSeq;
import rx.Observable;
import rx.Subscriber;
import java.util.function.Function;
/*
* Extensions for leveraging Rx Observable operators with cyclops-react ReactiveSeq instances
*
*
* {@code
* ReactiveSeq.of(1,2,3)
.to(lift(new Observable.Operator(){
@Override
public Subscriber super Integer> call(Subscriber super Integer> subscriber) {
return subscriber; // operator code
}
}))
.map(i->i+1)
.to(observable(o->o.buffer(10)));
}
*
*
*/
public class RxOperators {
public static Function,ReactiveSeq> lift(final Observable.Operator extends R, ? super T> operator){
return s->Observables.reactiveSeq(Observables.observableFrom(s).lift(operator));
}
public static Function,ReactiveSeq> observable(final Function super Observable super T>,? extends Observable extends R>> fn){
return s->Observables.reactiveSeq(Observables.narrow(fn.apply(Observables.observableFrom(s))));
}
public static Function,Observable> seq(final Function super ReactiveSeq super T>,? extends ReactiveSeq extends R>> fn){
return s-> Observables.observableFrom((ReactiveSeq)fn.apply(Observables.reactiveSeq(s)));
}
}