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_reduce

crates.io ci codecov license

Fold values and emit only the final accumulator on completion.

See Also

  • ScanOperator - Accumulate state and emit every intermediate result.

Example

cargo run -p rx_core --example operator_reduce_example
let _subscription = (0..=10)
    .into_observable()
    .reduce(|acc, next| acc + next, 0)
    .subscribe(PrintObserver::new("reduce_operator"));

Output:

reduce_operator - next: 55
reduce_operator - completed
reduce_operator - unsubscribed