com.github.davidmoten.rx.OperationToOperator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxjava-jdbc Show documentation
Show all versions of rxjava-jdbc Show documentation
rx-java Observables for jdbc
package com.github.davidmoten.rx;
import rx.Observable;
import rx.Observable.Operator;
import rx.Subscriber;
import rx.functions.Func1;
import rx.observers.Subscribers;
import rx.subjects.PublishSubject;
/**
* Converts an Operation (a function converting one Observable into another)
* into an {@link Operator}.
*
* @param
* to type
* @param
* from type
*/
public final class OperationToOperator implements Operator {
public static Operator toOperator(Func1, Observable> operation) {
return new OperationToOperator(operation);
}
/**
* The operation to convert.
*/
private final Func1, Observable> operation;
/**
* Constructor.
*
* @param operation
* to be converted into {@link Operator}
*/
public OperationToOperator(Func1, Observable> operation) {
this.operation = operation;
}
@Override
public Subscriber super T> call(Subscriber super R> subscriber) {
final PublishSubject subject = PublishSubject.create();
Subscriber result = Subscribers.from(subject);
subscriber.add(result);
operation.call(subject).unsafeSubscribe(subscriber);
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy