Created
May 3, 2021 08:46
-
-
Save armanozak/1038db6db73803037d4a7225c70903ae to your computer and use it in GitHub Desktop.
[What's New in RxJS 7] Better types in groups created by groupBy #blog #rxjs
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
import { of } from "rxjs"; | |
import { groupBy, map, mergeMap } from "rxjs/operators"; | |
// Observable<string, number> | |
of(0, "A", 1, "B", 2, "C", 3, "D", 4, "E", 5, "F", 6, "G", 7, "H", 8, "I", 9, "...") | |
.pipe( | |
groupBy((x): x is number => typeof x === "number"), | |
mergeMap(group$ => (group$.key === true ? group$.pipe(map(String)) : group$)) | |
) | |
.subscribe(); | |
// Observable<string> (in RxJS 6 → Observable<string | number>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment