In Reactive Programming, operators take one or several input streams and return a new stream. Some operators may accept additional arguments, such as functions:
These functions don’t have to work with the input or the output stream: they usually just transform, compare or combine values. The operators do work with the streams, in conjunction with these functions.
How you label a function (eg. “project” or “predicate” function) depends on how you use it.
A function that:
values
new value
of any typemay be used as a project function on combining operators (eg. combineLatest or zip).
A function that:
value
new value
of any typemay be used as a project function with map.
A function that:
value
new value
of type boolean
(✔ true
or ✘ false
)may be used as a predicate function on filtering operators (eg. filter, takeWhile or skipWhile)
As you may have noticed, a function used as a predicate can also be used as project function on a map operator:
In this example, the function n
⟶ n
== 1
, that returns ✔ true
or ✘ false
, is used both as an argument for map as a project and for filter as a predicate. As a result:
boolean
values, according to the result of this project function✔ true
Freelance Developer Advocate. Motion graphics with code. JavaScript and Elm. cedricsoulas.com
Receive my latest news, product updates and programming visualizations. You can unsubscribe at any time.