Documentation / @eventkit/base / pipe
Function: pipe()
ts
function pipe(): <T>(x) => T
Creates a new function that pipes the value through a series of functions.
The pipe()
function is used to create custom operators by combining multiple existing operators. It takes a sequence of operators and returns a new operator that applies each function in sequence, passing the result of one function as input to the next.
This is particularly useful for creating reusable sequences of operators that can be applied to observables.
Returns
Function
A function that represents the composition of all input functions
Type Parameters
Type Parameter |
---|
T |
Parameters
Parameter | Type |
---|---|
x | T |
Returns
T
Example
ts
// Create a custom operator that filters even numbers and doubles them
function doubleEvens() {
return pipe(
filter((num: number) => num % 2 === 0),
map((num) => num * 2)
);
}
// Use the custom operator
const result = AsyncObservable.from([1, 2, 3, 4])
.pipe(doubleEvens())
.subscribe(console.log);
// Outputs: 4, 8