Created
September 21, 2023 15:32
-
-
Save kirpachov/2f9fc1d7d9fad6bbacef7b567fe702e6 to your computer and use it in GitHub Desktop.
Snippets of things I've done once but I'll probably need again
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Emit each element of array as single event. | |
*/ | |
const array$: Subject<string[]> = new Subject<string[]>(); | |
const each$: Observable<string> = array$.pipe( | |
tap((v: string[]) => console.log('array', v)), | |
switchMap((array: string[]) => merge(...(array.map((item: string) => of(item))))), | |
tap((v: string) => console.log('each', v)), | |
); | |
each$.subscribe(); | |
array$.next(['a', 'b', 'c']); | |
// Console: | |
// array [ 'a', 'b', 'c' ] | |
// each a | |
// each b | |
// each c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment