2018-02-27 17:06:06 -05:00
|
|
|
import { of, pipe } from 'rxjs';
|
2018-01-09 11:31:41 -08:00
|
|
|
|
|
|
|
// #docregion
|
|
|
|
|
|
|
|
import { filter, map } from 'rxjs/operators';
|
|
|
|
|
2018-02-27 17:06:06 -05:00
|
|
|
const nums = of(1, 2, 3, 4, 5);
|
2018-01-09 11:31:41 -08:00
|
|
|
|
|
|
|
// Create a function that accepts an Observable.
|
|
|
|
const squareOddVals = pipe(
|
2018-07-18 11:55:36 +05:30
|
|
|
filter((n: number) => n % 2 !== 0),
|
2018-01-09 11:31:41 -08:00
|
|
|
map(n => n * n)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Create an Observable that will run the filter and map functions
|
|
|
|
const squareOdd = squareOddVals(nums);
|
|
|
|
|
|
|
|
// Suscribe to run the combined functions
|
|
|
|
squareOdd.subscribe(x => console.log(x));
|
|
|
|
|
|
|
|
// #enddocregion
|
|
|
|
|
|
|
|
|