Skip to content

Function: pipe() ​

pipe<InitArg>(arg): object

Defined in: builder.ts:90

Immediately applies (pipes) a value through a series of functions in order.

Uses a fluent builder for applying transformations to a value using method chaining.

It's an alternative syntax for creating complex compositions with the pipe function. Instead of nesting function calls, you can chain .andThen() calls to build your pipeline step by step, then call .run() to get the final result.

Unlike the pipe function, it doesn't have a limit on the number of functions that can be chained.

Type Parameters ​

InitArg ​

InitArg

The type of the initial value

Parameters ​

arg ​

InitArg

The initial value to transform

Returns ​

object

A builder object with andThen() method for chaining transformations and run() method to execute the pipeline

andThen() ​

andThen: <NextReturn>(nextFn) => object

Type Parameters ​

NextReturn ​

NextReturn

Parameters ​

nextFn ​

Fn<InitArg, NextReturn>

Returns ​

object

andThen() ​

andThen: <NextReturn>(nextFn) => object

Type Parameters ​
NextReturn ​

NextReturn

Parameters ​
nextFn ​

Fn<NextReturn, NextReturn>

Returns ​

object

andThen() ​

andThen: <NextReturn>(nextFn) => object

Type Parameters ​
NextReturn ​

NextReturn

Parameters ​
nextFn ​

Fn<NextReturn, NextReturn>

Returns ​

object

andThen() ​

andThen: <NextReturn>(nextFn) => object

Type Parameters ​
NextReturn ​

NextReturn

Parameters ​
nextFn ​

Fn<NextReturn, NextReturn>

Returns ​

object

andThen() ​

andThen: <NextReturn>(nextFn) => object

Type Parameters ​
NextReturn ​

NextReturn

Parameters ​
nextFn ​

Fn<..., ...>

Returns ​

object

andThen ​

andThen: ...

run ​

run: ...

run() ​

run: () => ... extends ... ? ... : ...

Returns ​

... extends ... ? ... : ...

run() ​

run: () => IsAsync<IsAsync<..., ...>, NextReturn> extends true ? Promise<Awaited<...>> : Awaited<NextReturn>

Returns ​

IsAsync<IsAsync<..., ...>, NextReturn> extends true ? Promise<Awaited<...>> : Awaited<NextReturn>

run() ​

run: () => IsAsync<Or<IsAsync<false, InitArg>, IsAsync<false, NextReturn>>, NextReturn> extends true ? Promise<Awaited<NextReturn>> : Awaited<NextReturn>

Returns ​

IsAsync<Or<IsAsync<false, InitArg>, IsAsync<false, NextReturn>>, NextReturn> extends true ? Promise<Awaited<NextReturn>> : Awaited<NextReturn>

run() ​

run: () => Or<IsAsync<false, InitArg>, IsAsync<false, NextReturn>> extends true ? Promise<Awaited<NextReturn>> : Awaited<NextReturn>

Returns ​

Or<IsAsync<false, InitArg>, IsAsync<false, NextReturn>> extends true ? Promise<Awaited<NextReturn>> : Awaited<NextReturn>

Examples ​

typescript
const result = pipe(5)
  .andThen((x) => x * 2)
  .andThen((x) => x + 1)
  .andThen((x) => x.toString())
  .run(); // "11"
typescript
const result = await pipe(5)
  .andThen((x) => x * 2)
  .andThen(async (x) => Promise.resolve(x + 1))
  .andThen((x) => x.toString())
  .run(); // "11"