pipe-ts
What is pipe
?
Overloads to supports up to 9 functions.
Installation
yarn add pipe-ts
npm install pipe-ts
pipe
Create a new function which pipes its value through the list functions.
const add1 = (n: number) => n + 1;
const times2 = (n: number) => n * 2;
const add1ThenTimes2 = pipe(
add1,
times2,
);
const result: number = add1ThenTimes2(1);
assert.strictEqual(result, 4);
Allows first function to have multiple parameters, using generic rest parameters
const difference = (a: number, b: number) => a - b;
const add1 = (n: number) => n + 1;
const differenceThenAdd1 = pipe(
difference,
add1,
);
const result: number = differenceThenAdd1(5, 4);
assert.strictEqual(result, 2);
pipeWith
Transform a value by piping it through the listed functions. Sugar syntax for pipe(f, g)(value)
.
const add1 = (n: number) => n + 1;
const times2 = (n: number) => n * 2;
const result: number = pipeWith(1, add1, times2);
assert.strictEqual(result, 4);
Development
yarn
npm run start