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 Null = undefined | null | |
type MVal<T> = T | Null | |
type Nullify<T> = { | |
[P in keyof T]: MVal<T[P]>; | |
}; | |
type MParams<T extends (...args: any) => any> = T extends (...args: infer P) => any ? Nullify<P> : never; | |
declare function apply<F extends (...args: any) => any>(f:F, ...args: Parameters<F>): ReturnType<F> | |
declare function mApply<F extends (...args: any) => any>(f:F, ...args: MParams<F>): MVal<ReturnType<F>> |
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 Null = undefined | null | |
type MVal<T> = T | Null | |
declare function mFn<T, R>(f:(a:T) => R): { | |
(a: T): R, | |
(a: Null): Null | |
} | |
declare function mFn<T, T2, R>(f:(a:T, b:T2) => R): { | |
(a: T, b:T2): R, |
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
const composeAsync = (...fs) => { | |
if (fs.length === 0) { | |
throw new Error('compose requires at least one argument') | |
} | |
return async (...as) => { | |
const call = async fs => { | |
const f = fs[0] | |
const tail = fs.slice(1, Infinity) | |
return await tail.length === 0 ? f(...as) : f(await call(tail)) |
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
const curry = f => { | |
const _curry = (args = []) => args.length < f.length ? (...a) => _curry([...args, ...a]) : f(...args) | |
return _curry() | |
} |