Skip to content

Instantly share code, notes, and snippets.

@kirpachov
Created September 21, 2023 15:32
Show Gist options
  • Save kirpachov/2f9fc1d7d9fad6bbacef7b567fe702e6 to your computer and use it in GitHub Desktop.
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
/**
* 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