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_count

crates.io ci codecov license

The count operator counts upstream emissions and emits the total once upstream completes.

See Also

  • IsEmptyOperator - Emit a single boolean indicating if the source emitted anything before it had completed.
  • FilterOperator - Keep values that satisfy a predicate.
  • ReduceOperator - Fold values and emit only the final accumulator on completion.

Example

cargo run -p rx_core --example operator_count_example
let _subscription = (1..=6)
  .into_observable()
  .filter(|value, _index| value % 2 == 0)
  .count()
  .subscribe(PrintObserver::new("count_operator"));

Output:

count_operator - next: 3
count_operator - completed
count_operator - unsubscribed