Skip to content

Instantly share code, notes, and snippets.

@zinoviy23
Created February 2, 2021 15:48
Show Gist options
  • Save zinoviy23/c929fdf19d1556860625ef1111d4e61c to your computer and use it in GitHub Desktop.
Save zinoviy23/c929fdf19d1556860625ef1111d4e61c to your computer and use it in GitHub Desktop.
Example of `doOnNext` on simple Reactive Stream
import io.reactivex.rxjava3.core.*;
public class Main {
public static void main(String[] args) throws InterruptedException {
Flowable.fromArray(1, 2, 3, 4, 5)
.doOnNext((i) -> System.out.println("1: " + i))
.map(i -> i + 1)
.doOnNext((i) -> System.out.println("2: " + i))
.filter(i -> i % 2 != 0)
.doOnNext((i) -> System.out.println("3: " + i))
.map(Integer::toBinaryString)
.doOnNext(i -> System.out.println("4: " + i))
.ignoreElements()
.blockingAwait();
}
}
@zinoviy23
Copy link
Author

Output with comments:

1: 1 // begin processing of 1
2: 2 // end processing of 1
1: 2 // begin processing of 2
2: 3
3: 3
4: 11 // end processing of 2
1: 3 // begin processing of 3
2: 4 // end processing of 3
1: 4 // begin processing of 4
2: 5
3: 5
4: 101 // end processing of 4
1: 5 // begin processing of 5
2: 6  // end processing of 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment