Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

operator_on_next

crates.io ci codecov license

Invoke a callback for each value that can also decide whether to forward it.

  • Returning true allows the value to be forwarded to the destination observer.
  • Returning false prevents the value from being forwarded.

Like filter, but with access to the destination observer!

See Also

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