O'Reilly logo

Mastering Reactive JavaScript by Erich de Souza Oliveira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The flatMapFirst() operator

This operator propagates data from the first mapped observable, and it only goes to the next when it finishes discarding all the other observables before finishing.

The flatMapFirst() operator has the following signature:

observable.flatMapFirst(selectorFunction,[selectorContext]); 

It receives up to two parameters; the first is mandatory and the second is optional:

  • selectorFunction: It is a function that maps a value to an observable sequence
  • selectorContext: In this parameter (context) used in the selectorFunction

An example usage of this operator can be seen in the following code:

Rx.Observable   .interval(50)   .flatMapFirst(     (i)=>Rx.Observable.interval(30)  .map((k)=>'running for: '+i+' flatMapFirst: '+k) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required