Skip to content

pipeLazy() function

创建执行从左到右函数组合的函数。所有参数必须是一元的。

Signature:

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

Example

ts
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

Open Source Code

Released under the Apache-2.0 License.