Skip to content

Instantly share code, notes, and snippets.

@traviskaufman
Created October 25, 2019 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save traviskaufman/25e0b59408ce6a3e8ba1255180959438 to your computer and use it in GitHub Desktop.
Save traviskaufman/25e0b59408ce6a3e8ba1255180959438 to your computer and use it in GitHub Desktop.
Demystifying RxJS, Part II: Custom operators
function computeSquaredSum(): OperatorFunction<number, number> {
return source =>
source.pipe(
map(n => n * n),
reduce((s, n) => s + n, 0),
);
}
oneThroughTen
.pipe(computeSquaredSum())
.subscribe(x => console.log("Squared sum w/ custom op =", x));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment