Filtering Observables

David Gross edited this page Jan 12, 2015 · 78 revisions

This page shows operators you can use to filter and select items emitted by Observables.

  • filter( ) — filter items emitted by an Observable
  • takeLast( ) — only emit the last n items emitted by an Observable
  • last( ) — emit only the last item emitted by an Observable
  • lastOrDefault( ) — emit only the last item emitted by an Observable, or a default value if the source Observable is empty
  • takeLastBuffer( ) — emit the last n items emitted by an Observable, as a single list item
  • skip( ) — ignore the first n items emitted by an Observable
  • skipLast( ) — ignore the last n items emitted by an Observable
  • take( ) — emit only the first n items emitted by an Observable
  • first( ) and takeFirst( ) — emit only the first item emitted by an Observable, or the first item that meets some condition
  • firstOrDefault( ) — emit only the first item emitted by an Observable, or the first item that meets some condition, or a default value if the source Observable is empty
  • elementAt( ) — emit item n emitted by the source Observable
  • elementAtOrDefault( ) — emit item n emitted by the source Observable, or a default item if the source Observable emits fewer than n items
  • sample( ) or throttleLast( ) — emit the most recent items emitted by an Observable within periodic time intervals
  • throttleFirst( ) — emit the first items emitted by an Observable within periodic time intervals
  • throttleWithTimeout( ) or debounce( ) — only emit an item from the source Observable after a particular timespan has passed without the Observable emitting any other items
  • timeout( ) — emit items from a source Observable, but issue an exception if no item is emitted in a specified timespan
  • distinct( ) — suppress duplicate items emitted by the source Observable
  • distinctUntilChanged( ) — suppress duplicate consecutive items emitted by the source Observable
  • ofType( ) — emit only those items from the source Observable that are of a particular class
  • ignoreElements( ) — discard the items emitted by the source Observable and only pass through the error or completed notification