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_is_empty

crates.io ci codecov license

The is_empty operator will emit a single boolean value indicating whether upstream emitted any items before completing:

  • If the upstream completes without emitting any items, is_empty will emit true and then complete.
  • If the upstream emits any items, is_empty will immediately emit false and complete.

Example

cargo run -p rx_core --example operator_is_empty_example
let _s = (1..=5)
    .into_observable()
    .is_empty() // Will stop the iterator, send `false`, then complete.
    .subscribe(PrintObserver::new("is_empty_operator - iterator"));

let _s = empty() // Immediately completes.
    .is_empty()
    .subscribe(PrintObserver::new("is_empty_operator - empty"));

Output:

is_empty_operator - iterator - next: false
is_empty_operator - iterator - completed
is_empty_operator - iterator - unsubscribed
is_empty_operator - empty - next: true
is_empty_operator - empty - completed
is_empty_operator - empty - unsubscribed