Created
March 17, 2024 02:15
-
-
Save guiseek/b8496410e20fcd81595f5b411cbafe93 to your computer and use it in GitHub Desktop.
Pipe functions
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
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