Skip to content

Instantly share code, notes, and snippets.

@guiseek
Created March 17, 2024 02:15
Show Gist options
  • Save guiseek/b8496410e20fcd81595f5b411cbafe93 to your computer and use it in GitHub Desktop.
Save guiseek/b8496410e20fcd81595f5b411cbafe93 to your computer and use it in GitHub Desktop.
Pipe functions
type Fn<T, R> = (value: T) => R;
type Pipe<T, R> = [Fn<T, R>, ...Fn<R, R>[]];
function pipe<T, R>(...[fn, ...fns]: Pipe<T, R>) {
return (value: T) => fns.reduce((p, c) => c(p), fn(value));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment