Pipe
Run the given functions in order from left to right, passing the output from the previous one as the input to the next one. This is useful for composing functions together.
Example usage
Section titled “Example usage”The below example combines two functions into a single one that runs each in order.
const splitEachCharacter = v => v.split('');
const parseArrayToNumbers = arr => arr.map(parseInt);
// Calling this composed function will now split the input
// and then parse each item to an int.
const parseStringToNumberArray = pipe(
splitEachCharacter,
parseArrayToNumbers
);
parseStringToNumberArray('12345');
/**
* Output:
* [1,2,3,4,5]
*/
Note on Typings
Section titled “Note on Typings”There isn’t really a good way to type a pipe function currently in TS. Some examples to attemp this are:
I have gone with a simple definition of the input and output expected. It is a bit more manual that you would usually want but as of writing this the required TS is not worth the result.