operator_take
Emit only the first n values, then complete.
See Also
- FilterOperator - Keep values that satisfy a predicate.
- FilterMapOperator -
Map values to an
Optionand keep only theSomevalues. - SkipOperator -
Drop the first
nvalues. - LiftOptionOperator -
Filter out
Noneand forwardSomevalues.
Example
cargo run -p rx_core --example operator_take_example
let _subscription = (1..=5)
.into_observable()
.take(2)
.subscribe(PrintObserver::new("take_operator"));
Output:
take_operator - next: 1
take_operator - next: 2
take_operator - completed
take_operator - unsubscribed