Last active
April 4, 2021 10:46
-
-
Save NyaGarcia/21fa56b270affd69da35e26cf371d524 to your computer and use it in GitHub Desktop.
Fixing duplicated logic smell by attaching takeUntil() to the source Observable
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 { from } from "rxjs"; | |
import { filter, reduce } from "rxjs/operators"; | |
const number$ = from([null, 2, 1, 0, 5, false, 6, 7]).pipe( | |
filter<number>(Boolean) | |
); | |
// Adding numbers | |
number$ | |
.pipe( | |
reduce((acc, curr) => acc + curr) | |
) | |
.subscribe(n => console.log(`Total: ${n}`)); | |
// Emit even numbers | |
number$ | |
.pipe( | |
filter(n => n % 2 === 0) | |
) | |
.subscribe(console.log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment