The process module contains functions for orchestrating a simple series of data transformations.
Use flow
to create this orchestration:
const p = flow(
(value:string) => value.toUpperCase(), // Convert to uppercase
(value:string) => value.at(0) === 'A') // If first letter is an A, return true
);
Once created, the flow can be invoked with an input value:
p('apple'); // True
Each function in the processing flow takes one input and returns one result. There are a few in-built functions as well. Some of these are stateful, remembering previous values that have been processed (eg seenToUndefined
).
Cancels the remaining flow operations if undefined is an input. See also ifUndefined or ifNotUndefined.
Creates a flow of data processors (up to 5 are supported). The flow is encapsulated in a function that accepts an input value an returns an output.
Calls a function if the input value is not undefined. Return value from function is passed to next function in flow.
Returns the output of fn
if the input value is undefined.
See also: ifNotUndefined and cancelIfUndefined.
Outputs the current largest-seen value
Outputs the current smallest-seen value
Returns the 'best' value seen so far as determined by a ranking function. This is similar to min/max but usable for objects.
If a value is same as the previous value, undefined is emitted instead.
If a value is same as any previously-seen value, undefined is emitted instead.
If a value is the same as any previously-seen value, undefined is emitted instead.
Returns a sum of values
Returns the tally (ie number of) values
A rank function that compares A and B. Returns the highest value, 'a' or 'b'. Returns 'eq' if values are equal
Returns the current average of input values