Skip to main content

Module: Composition

Type Aliases

Compose

Ƭ Compose<Arguments, Functions>: Arguments["length"] extends 0 ? Functions : Arguments extends [infer A, infer B] ? [...Functions, (arg: A) => B] : Arguments extends [infer A, ...(infer Rest), infer P, infer L] ? Compose<[A, ...Rest, P], [...Functions, (arg: P) => L]> : []

Makes a composition of functions from received arguments.

Type parameters

NameType
Argumentsextends any[]
Functionsextends any[] = []

Decompose

Ƭ Decompose<Functions, Arguments>: Functions extends [(arg: infer Arg) => infer Return] ? [...Arguments, Arg, Return] : Functions extends [...(infer Rest extends UnaryFunction[]), (arg: infer Arg) => any] ? Decompose<Rest, [...Arguments, Arg]> : []

Destructures a composition of functions into arguments.

Type parameters

NameType
Functionsextends UnaryFunction[]
Argumentsextends any[] = []

Depipe

Ƭ Depipe<Functions, Arguments>: Functions extends [(arg: infer Arg) => infer Return] ? [...Arguments, Arg, Return] : Functions extends [(arg: infer Arg) => any, ...(infer Rest extends UnaryFunction[])] ? Depipe<Rest, [...Arguments, Arg]> : []

Destructures a pipeline of functions into arguments.

Type parameters

NameType
Functionsextends UnaryFunction[]
Argumentsextends any[] = []

Pipe

Ƭ Pipe<Arguments, Functions>: Arguments["length"] extends 0 ? Functions : Arguments extends [infer A, infer B] ? [(arg: A) => B, ...Functions] : Arguments extends [infer A, ...(infer Rest), infer P, infer L] ? Pipe<[A, ...Rest, P], [(arg: P) => L, ...Functions]> : []

Makes a pipeline of functions from received arguments.

Type parameters

NameType
Argumentsextends any[]
Functionsextends any[] = []

Functions

compose

compose<A, B, C>(f, g): (...args: A) => C

(B -> C) . (A -> B) = A -> C

Type parameters

NameType
Aextends any[]
BB
CC

Parameters

NameType
f(arg: B) => C
g(...args: A) => B

Returns

fn

▸ (...args): C

Parameters
NameType
...argsA
Returns

C

compose<A, B, C>(f, g, ...args): C

(B -> C) . (A -> B) = A -> C

Type parameters

NameType
Aextends any[]
BB
CC

Parameters

NameType
f(arg: B) => C
g(...args: A) => B
...argsA

Returns

C


pipe

pipe<A, B, C>(f, g): (...args: A) => C

(A -> B) . (B -> C) = A -> C

Type parameters

NameType
Aextends any[]
BB
CC

Parameters

NameType
f(...args: A) => B
g(arg: B) => C

Returns

fn

▸ (...args): C

Parameters
NameType
...argsA
Returns

C

pipe<A, B, C>(...args): C

(A -> B) . (B -> C) = A -> C

Type parameters

NameType
Aextends any[]
BB
CC

Parameters

NameType
...args[...args: A[], f: Function, g: Function]

Returns

C