Skip to content

Instantly share code, notes, and snippets.

@Drag13
Last active November 12, 2021 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Drag13/143a492af553d90d5b506a3e25eabb98 to your computer and use it in GitHub Desktop.
Save Drag13/143a492af553d90d5b506a3e25eabb98 to your computer and use it in GitHub Desktop.
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