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_switch_map

crates.io ci codecov license

Map each value to an inner observable and switch to the latest, unsubscribing previous ones.

See Also

  • ConcatAllOperator - Subscribes to upstream observables one at a time in order.
  • MergeAllOperator - Subscribes to upstream observables and merges their emissions concurrently.
  • SwitchAllOperator - Switch to the newest inner observable, unsubscribing previous ones.
  • ExhaustAllOperator - Ignore new inner observables while one is active.
  • ConcatMapOperator - Map each value to an inner observable and subscribe to them one at a time in order.
  • MergeMapOperator - Map each value to an inner observable and merge their emissions concurrently.
  • ExhaustMapOperator - Map each value to an inner observable and ignore new ones while one is active.

Example

cargo run -p rx_core --example operator_switch_map_operator_example
let _subscription = (1..=3)
    .into_observable()
    .switch_map(|next| IteratorObservable::new(1..=next), Never::map_into())
    .subscribe(PrintObserver::new("switch_map"));

Output:

switch_map - next: 1
switch_map - next: 1
switch_map - next: 2
switch_map - next: 1
switch_map - next: 2
switch_map - next: 3
switch_map - completed
switch_map - unsubscribed