Skip to main content

pipeLazy

pipeLazy() function

Make function, that performs left to right function composition. All arguments must be unary.

Signature:

declare function pipeLazy<T1, R>(f1: (a: Awaited<T1>) => R): ((a: T1) => ReturnPipeType<[T1, R]>) & ((a: Promise<T1>) => ReturnPipeType<[Promise<T1>, R]>);

Returns:

((a: T1) => ReturnPipeType<[T1, R]>) & ((a: Promise<T1>) => ReturnPipeType<[Promise<T1>, R]>)

Example

pipeLazy(
map(a => a + 10),
filter(a => a % 2 === 0),
toArray,
)([1, 2, 3, 4, 5]); // [12, 14]

await pipeLazy(
map(a => a + 10),
filter(a => a % 2 === 0),
toArray,
)(Promise.resolve([1, 2, 3, 4, 5])); // [12, 14]

// if you want to use asynchronous callback
await pipeLazy(
toAsync,
map(async (a) => a + 10),
filter((a) => a % 2 === 0),
toArray,
)(Promise.resolve([1, 2, 3, 4, 5])); // [12, 14]

// with toAsync
await pipeLazy(
toAsync,
map(a => a + 10),
filter(a => a % 2 === 0),
toArray,
)([Promise.resolve(1), Promise.resolve(2), Promise.resolve(3), Promise.resolve(4), Promise.resolve(5)]); // [12, 14]

see toAsync, map, filter