Purity and the Observable Pipeline
An Observable pipeline is a group of operators chained together, where each one takes an Observable as input and returns an Observable as output. We’ve been using pipelines in this book; they are ubiquitous when programming with RxJS. Here’s a simple one:
| Observable |
| .from([1, 2, 3, 4, 5, 6, 7, 8]) |
| .filter(val => val % 2) |
| .map(val => val * 10); |
Pipelines are self-contained. All state flows from one operator to the next without the need for any external variables. This way we avoid external state (we talked about external state in Side Effects and External State). We accomplish this by using pure functions.
Pure functions always return the same output given the same input. It’s easier ...
Get Reactive Programming with RxJS 5 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.