Wednesday, March 28, 2018

An Observable pipe, not to be confused with an Angular pipe, allows for outside pure functions to be used in midstream mapesque transformations.

Stack Overflow here has the following example which both returns the number fifty and seems to have some missing semicolons.

const { Observable } = require('rxjs/Rx')
const { filter, map, reduce, } = require('rxjs/operators')
const { pipe } = require('rxjs/Rx')
 
const filterOutEvens = filter(x => x % 2)
const doubleBy = x => map(value => value * x);
const sum = reduce((acc, next) => acc + next, 0);
const source$ = Observable.range(0, 10)
 
source$.pipe(
   filterOutEvens,
   doubleBy(2),
   sum)
   .subscribe(console.log);

No comments:

Post a Comment