liveBook · Manning

Operator

As explained in The Joy of JavaScript

A composable function or transformation that processes an observable sequence or stream element by element.

An operator is a composable function or transformation that processes values emitted by an Observable. It changes the stream before values reach a subscriber, usually by returning a new Observable that can be chained with other operators. section 1.5 section 9.4.3

Operators provide the points where a stream changes course. A custom operator subscribes to its source, handles next, error, and complete notifications, and returns an unsubscribe function so cancellation propagates upstream. section 9.4.3 section 9.4.1

Common custom operators illustrate different stream transformations:

  • map applies a function to every emitted value and produces transformed values. section 9.4.3
  • filter forwards only values satisfying a predicate. section 9.4.3
  • reduce accumulates values and emits the final result when the source completes. section 9.4.3
  • skip suppresses an initial number of values before forwarding subsequent emissions. section 9.4.3

Composing a stream pipeline

A pipeline can skip the first value, keep even values, square them, and add the results: reduce(add, 0, map(square, filter(isEven, skip(1, obs)))). With Observable.of(1, 2, 3, 4), the subscriber receives 20.

How The Joy of JavaScript covers it

How deep it goes
Builds custom map, filter, reduce, and skip operators, including subscription, notification, composition, and cancellation mechanics.
Examples
Uses random-number streams, mapped number sequences, nested pipelines, and a skip-filter-map-reduce calculation producing 20.
What it assumes
Assumes familiarity with JavaScript functions and Observable subscription while teaching operator composition through concrete implementations.
What you can do after
Build it from scratch by implementing custom operators that transform, select, accumulate, or suppress Observable emissions.
How it connects
Connects Observable, Observer, Subscription, higher-order functions, composition, lazy evaluation, and algebraic data types.

Also explained in

Compare how 2 books explain operator →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Joy of JavaScript. The section links point to the parts of the book it draws on.