Creating reusable operators with let()

The let() operator lets you have the whole operator and operate on it, rather than just manipulating the values as you would do with the map() operator, for example. Using the let() operator could look like this:

import Rx from "rxjs/Rx";

let stream = Rx.Observable.of(0,1,2);
let addAndFilter = obs => obs.map( x => x * 10).filter(x => x % 10 === 0);
let sub3 = obs => obs.map(x => x - 3);

stream
.let(addAndFilter)
.let(sub3)
.subscribe(x => console.log('let', x));

In the preceding example, we were able to define a group of operators such as addAndFilter and sub3 and use them on the stream with the let() operator. This enables us to create composable and reusable operators. It is with this very knowledge that we now move on to the concept of pipeable operators.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.190.41