Skip to content

Commit

Permalink
docs: update Operators overview (#6819)
Browse files Browse the repository at this point in the history
Introduce the concept that what we normally call "operators", such as `map`
or `filter`, are Pipeable Operator Factory functions which, when called,
return a "real" Pipeable Operator.

(cherry picked from commit a292214)
  • Loading branch information
EnricoPicci authored and jakovljevic-mladen committed Mar 31, 2023
1 parent 25bde17 commit 6adc66f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docs_app/content/guide/operators.md
Expand Up @@ -6,10 +6,14 @@ RxJS is mostly useful for its _operators_, even though the Observable is the fou

Operators are **functions**. There are two kinds of operators:

**Pipeable Operators** are the kind that can be piped to Observables using the syntax `observableInstance.pipe(operator())`. These include, [`filter(...)`](/api/operators/filter), and [`mergeMap(...)`](/api/operators/mergeMap). When called, they do not _change_ the existing Observable instance. Instead, they return a _new_ Observable, whose subscription logic is based on the first Observable.
**Pipeable Operators** are the kind that can be piped to Observables using the syntax `observableInstance.pipe(operator)` or, more commonly, `observableInstance.pipe(operatorFactory())`. Operator factory functions include, [`filter(...)`](/api/operators/filter), and [`mergeMap(...)`](/api/operators/mergeMap).

When Pipeable Operators are called, they do not _change_ the existing Observable instance. Instead, they return a _new_ Observable, whose subscription logic is based on the first Observable.

<span class="informal">A Pipeable Operator is a function that takes an Observable as its input and returns another Observable. It is a pure operation: the previous Observable stays unmodified.</span>

<span class="informal">A Pipeable Operator Factory is a function that can take parameters to set the context and return a Pipeable Operator. The factory’s arguments belong to the operator’s lexical scope.</span>

A Pipeable Operator is essentially a pure function which takes one Observable as input and generates another Observable as output. Subscribing to the output Observable will also subscribe to the input Observable.

**Creation Operators** are the other kind of operator, which can be called as standalone functions to create a new Observable. For example: `of(1, 2, 3)` creates an observable that will emit 1, 2, and 3, one right after another. Creation operators will be discussed in more detail in a later section.
Expand Down

0 comments on commit 6adc66f

Please sign in to comment.