Hullo JS
Search…
|> flatMap
import { flatMap } from '@hullo/core'
Use this operator in case you want to release multiple values on every source one. On every message of a source Observable, transforming function is expected to return an Observable that will contain values that'll be pushed through resulting Observable.
Since every reader can regulate pressure, flatMap will not mix messages from one observable with another. It'll even not try to get next flatMap-produced-observable as it'll not acknowledge receiving previous one until it is completed.
Following example will double the message without changing them further:
1
import { Observable, flatMap } from '@hullo/core';
2
​
3
new Observable(observer => {
4
observer.next('echo');
5
observer.next('ECHO');
6
observer.next('EEECHOOO');
7
})
8
.pipe(flatMap(v => observable(observer => {
9
/* here source message is repeated
10
* into a separate Observable */
11
observer.next(v);
12
observer.next(v);
13
})
14
.subscribe({
15
next: v => { console.log(v): }
16
});
17
18
/* Prints:
19
* echo
20
* echo
21
* ECHO
22
* ECHO
23
* EEECHOOO
24
* EEECHOOO
25
*/
Copied!
Last modified 2yr ago
Copy link