Skip to content

Instantly share code, notes, and snippets.

@typoerr
Created January 27, 2018 06:02
Show Gist options
  • Save typoerr/4b2587f2647e764967d34bca8eab5d41 to your computer and use it in GitHub Desktop.
Save typoerr/4b2587f2647e764967d34bca8eab5d41 to your computer and use it in GitHub Desktop.
export function combine<A, R1, R>(funcs: [Func1<A, R1>]): (value: A) => [R1]
export function combine<A, R1, R>(funcs: [Func1<A, R1>], project: (value: [R1]) => R): Func1<A, R>
export function combine<A, R1, R2, R>(funcs: [Func1<A, R1>, Func1<A, R2>]): Func1<A, [R1, R2]>
export function combine<A, R1, R2, R>(funcs: [Func1<A, R1>, Func1<A, R2>], project: (value: [R1, R2]) => R): Func1<A, R>
export function combine<A, R1, R2, R3, R>(funcs: [Func1<A, R1>, Func1<A, R2>, Func1<A, R3>]): Func1<A, [R1, R2, R3]>
export function combine<A, R1, R2, R3, R>(funcs: [Func1<A, R1>, Func1<A, R2>, Func1<A, R3>], project: (value: [R1, R2, R3]) => R): Func1<A, R>
export function combine<A, R1, R2, R3, R4, R>(funcs: [Func1<A, R1>, Func1<A, R2>, Func1<A, R3>, Func1<A, R4>]): Func1<A, [R1, R2, R3, R4]>
export function combine<A, R1, R2, R3, R4, R>(
funcs: [Func1<A, R1>, Func1<A, R2>, Func1<A, R3>, Func1<A, R4>],
project: (value: [R1, R2, R3, R4]) => R): Func1<A, R>
export function combine(funcs: Function[], project: Function = identity): Function {
return function (this: any) {
const results: any[] = []
for (let i = 0; i < funcs.length; i++) {
results.push(funcs[i].apply(this, arguments))
}
return project(results)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment