Last active
November 12, 2021 14:02
-
-
Save Drag13/143a492af553d90d5b506a3e25eabb98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function pipe<I, R1, R>(f1: (a: I) => R1, f2: (a: R1) => R): (a: I) => R; | |
export function pipe<I, I1, R1, R>(f1: (a: I, b: I1) => R1, f2: (a: R1) => R): (a: I, b: I1) => R; | |
export function pipe<I, R1, R2, R>( | |
f1: (a: I) => R1, | |
f2: (a: R1) => R2, | |
f3: (a: R2) => R | |
): (a: I) => R; | |
export function pipe<I, I1, R1, R2, R>( | |
f1: (a: I, b?: I1) => R1, | |
f2: (a: R1) => R2, | |
f3: (a: R2) => R | |
): (a: I, b?: I1) => R; | |
export function pipe<I, R>(): (a: I) => R { | |
const args = Array.from(arguments); | |
return function executer(...a) { | |
return args.reduce( | |
(prevResult, f) => (Array.isArray(prevResult) ? f(...prevResult) : f(prevResult)), | |
a | |
); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment