operator_on_next
Invoke a callback for each value that can also decide whether to forward it.
- Returning
trueallows the value to be forwarded to the destination observer. - Returning
falseprevents the value from being forwarded.
Like
filter, but with access to the destination observer!
See Also
- TapOperator - Mirror all signals into another observer.
- TapNextOperator -
Run a callback for each
nextvalue while letting signals pass through. - OnSubscribeOperator - Run a callback when a subscription is established.
- FinalizeOperator - Execute cleanup when the observable finishes or unsubscribes.
Example
cargo run -p rx_core --example operator_on_next_example
let _subscription = (1..=5)
.into_observable()
.on_next(|next, destination| {
destination.next(next * 99);
true
})
.subscribe(PrintObserver::new("on_next_operator"));
Output:
on_next_operator - next: 99
on_next_operator - next: 1
on_next_operator - next: 198
on_next_operator - next: 2
on_next_operator - next: 297
on_next_operator - next: 3
on_next_operator - next: 396
on_next_operator - next: 4
on_next_operator - next: 495
on_next_operator - next: 5
on_next_operator - completed
on_next_operator - unsubscribed