Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Latest commit

 

History

History
72 lines (58 loc) · 2.77 KB

flatmapfirst.md

File metadata and controls

72 lines (58 loc) · 2.77 KB

Rx.Observable.prototype.flatMapFirst(selector, [thisArg])

Rx.Observable.prototype.selectSwitchFirst(selector, [thisArg])

Transform the items emitted by an Observable into Observables, and mirror those items emitted by the most-recently transformed Observable.

The flatMapFirst operator is similar to the flatMap and concatMap methods described above, however, rather than emitting all of the items emitted by all of the Observables that the operator generates by transforming items from the source Observable, flatMapFirst instead propagates the first Observable exclusively until it completes before it begins subscribes to the next Observable. Observables that come before the current Observable completes will be dropped and will not propagate.

Arguments

  1. selector (Function): A transform function to apply to each source element. The callback has the following information:
    1. the value of the element
    2. the index of the element
    3. the Observable object being subscribed
  2. [thisArg] (Any): Object to use as this when executing the predicate.

Returns

(Observable): An Observable sequence that is the result of concatenating non-overlapping items emitted by an Observable of Observables.

Example

//Generate an event every 100 milliseconds
var source = Rx.Observable.generateWithRelativeTime(
   0,
   function(x) {return x < 5; },
   function(x) {return x + 1; },
   function(x) {return x; },
   function(x) {return 100; })
  .flatMapFirst(function(value) {
    //Observable takes 150 milliseconds to complete
    return Rx.Observable.timer(150).map(value);
  });

var subscription = source.subscribe(
  function (x) {
    console.log('Next: %d', x);
  },
  function (err) {
    console.log('Error: %s', err);
  },
  function () {
    console.log('Completed');
  });

// Next: 0
// Next: 2
// Next: 4
// Completed

Location

File:

Dist:

Prerequisites:

  • None

NPM Packages:

NuGet Packages:

Unit Tests:

  • None