-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Step-by-step guide for writing a custom operator? #5862
Comments
This shouldn't be of any difficulty because the two modes are only a straighforward transformation away: You write the operator: final class SomeOp<T> implements FlowableSubscriber<T>, Subscription {
// etc
} Optionally turn it into a liftable expression: FlowableOperator<T, T> op = downstream -> new SomeOp<>(downstream, params);
Flowable.range(1, 5).lift(op).subscribe(System.out::println); Or turn it into a transformer: FlowableTransformer<T, T> ft = upstream -> new Flowable<T>() {
@Override public void subscribeActual(Subscriber<? super T> downstream) {
upstream.subscribe(new SomeOp<>(downstream, params));
}
};
Flowable.range(1, 5).compose(ft).subscribe(System.out::println); or use lifting and a transformer: FlowableTransformer<T, T> ft2 = upstream -> updstream.lift(op);
Flowable.range(1, 5).compose(ft2).subscribe(System.out::println); |
You could also read my blog and study the RxJava source code. |
Thanks, I will certainly study. But sometimes, you know, there's just no substitute for a fully worked-out example. A large part of my problem is that the documentation of
Could someone please try to explain in simple terms what Final question: once I have created an operator, how do I "insert" it into the |
No, it warns the user about the complexities of using it and then suggests using existing operators, such as
You can't add a new operator to Therefore, you either write As a final note, I don't suggest you write operators if you are just learning RxJava, the target platform, the Java language or programming itself. |
Please see PR #5863 for the suggested expansion of the JavaDoc of |
Closing via #5863. |
I've been trying, with limited success, to understand the discussion of creating custom 2.x operators. I think I get the section "Operator by extending a base reactive class", but what would really help for the "Operator targeting lift()" discussion is a complete, design-through-usage example of creating an operator. Is this possible?
Suggestion: a simple operator that transforms its input type, perhaps something like
.countCharacters()
that would accept aString
and emit anInteger
with the number of characters in theString
. If possible, versions with and without backpressure would be extra helpful.The text was updated successfully, but these errors were encountered: