UNPKG

@rwk/physics-math

Version:
98 lines 4.29 kB
/** * Turn a function of 1-4 arguments into one that auto-curries. * Any arguments omitted or supplied as undefined will result in a new function being returned * that accepts the missing arguments. * * If all arguments are supplied, the supplied function is called and the value returned. * If no arguments are supplied, the same autocurried function is returned. * @packageDocumentation * @module Utils */ /** * @internal */ export interface Function1<R, A> { (a: A): R; (a?: undefined): Function1<R, A>; } export declare function curry1<R, A>(f: (a: A) => R): Function1<R, A>; /** * @internal */ export interface Function2<R, A, B> { (a: A, b: B): R; (a: undefined, b: B): Function1<R, A>; (a: A, b?: undefined): Function1<R, B>; (a?: undefined, b?: undefined): Function2<R, A, B>; } /** * Take a function of two arguments, and return one that auto-curries. If any of the arguments is * undefined, return a function that accepts that argument. * * If both arguments are undefined, returns itself. * If both arguments are defined, immediately calls f with those arguments * if a is undefined, return a => f(a, b) * if b is undefined, return b => f(a, b) * @param f a function of two arguments. */ export declare function curry2<R, A, B>(f: (a: A, b: B) => R): Function2<R, A, B>; /** * @internal */ export interface Function3<R, A, B, C> { (a: A, b: B, c: C): R; (a: undefined, b: B, c: C): Function1<R, A>; (a: A, b: undefined, c: C): Function1<R, B>; (a: A, b: B, c?: undefined): Function1<R, C>; (a: A, b?: undefined, c?: undefined): Function2<R, B, C>; (a: undefined, b: B, c?: undefined): Function2<R, A, C>; (a: undefined, b: undefined, c: C): Function2<R, A, B>; (a?: undefined, b?: undefined, c?: undefined): Function3<R, A, B, C>; } /** * Take a function of three arguments, and return one that auto-curries. If any of the arguments are * undefined, return a function that accepts that argument. * * If all arguments are undefined, returns itself. * If all arguments are defined, immediately calls f with those arguments * if a is undefined, return a => f(a, b, c) * if b is undefined, return b => f(a, b, c) * if c is undefined, return c => f(a, b, c) * @param f a function of three arguments. */ export declare function curry3<R, A, B, C>(f: (a: A, b: B, c: C) => R): Function3<R, A, B, C>; /** * @internal */ export interface Function4<R, A, B, C, D> { (a: A, b: B, c: C, d: D): R; (a: undefined, b: B, c: C, d: D): Function1<R, A>; (a: A, b: undefined, c: C, d: D): Function1<R, B>; (a: A, b: B, c: undefined, d: D): Function1<R, C>; (a: A, b: B, c: C, d?: undefined): Function1<R, D>; (a: A, b: B, c?: undefined, d?: undefined): Function2<R, C, D>; (a: A, b: undefined, c: C, d?: undefined): Function2<R, B, D>; (a: A, b: undefined, c: undefined, d: D): Function2<R, B, C>; (a: undefined, b: undefined, c: C, d: D): Function2<R, A, B>; (a: undefined, b: B, c: undefined, d: D): Function2<R, A, C>; (a: undefined, b: B, c: C, d?: undefined): Function2<R, A, D>; (a: A, b?: undefined, c?: undefined, d?: undefined): Function3<R, B, C, D>; (a: undefined, b: B, c?: undefined, d?: undefined): Function3<R, A, C, D>; (a: undefined, b: undefined, c: C, d?: undefined): Function3<R, A, B, D>; (a: undefined, b: undefined, c: undefined, d: D): Function3<R, A, B, C>; (a?: undefined, b?: undefined, c?: undefined, d?: undefined): Function4<R, A, B, C, D>; } /** * Take a function of four arguments, and return one that auto-curries. If any of the arguments are * undefined, return a function that accepts that argument. * * If all arguments are undefined, returns itself. * If all arguments are defined, immediately calls f with those arguments * if a is undefined, return a => f(a, b, c, d) * if b is undefined, return b => f(a, b, c, d) * if c is undefined, return c => f(a, b, c, d) * if d is undefined, return d => f(a, b, c, d) * @param f a function of four arguments. */ export declare function curry4<R, A, B, C, D>(f: (a: A, b: B, c: C, d: D) => R): Function4<R, A, B, C, D>; //# sourceMappingURL=curry.d.ts.map