[RxJS] Chain RxJS Operators Together with a Custom `pipe` Function using Array.reduce
Instead of writing complex operators, it's usually best to write simple, single-purpose operators then chain them together when necessary. The pipe
function takes functions as arguments, invokes each function with the value, then passes the returned result on to the next function.
build a custom pipe function:
const pipe = (...fns) => source => fns.reduce((acc, fn) => fn(acc), source);
import { map, filter } from "rxjs/operators"; export const mul = number => pipe( map(v => v * number), filter(v => v < 10) );