a curried function that consumes variable number of arguments, until all required parameters are available, after which a return value is spat out
import { assertEquals as assertEq } from "jsr:@std/assert"
const abcd = (a: number, b: string, c: boolean, d: symbol): string => (String(a) + b + String(c) + " " + String(d))
const abcd_diversity_curry = curryMulti(abcd)
abcd_diversity_curry satisfies CurryMultiSignature<(a: number, b: string, c: boolean, d: symbol) => string, string, any>
assertEq(
(((abcd_diversity_curry(
42, " hello to za warudo! ") satisfies CurryMultiSignature<(c: boolean, d: symbol) => string, string, any>
)(true) satisfies CurryMultiSignature<(d: symbol) => string, string, any>
)(Symbol.iterator) satisfies (string)
),
"42 hello to za warudo! true Symbol(Symbol.iterator)",
)
come here, come all! greet the Types' Olympic Champion of winter 2024.
it took a while to correctly apply a multitude of gymnastics to get it functioning, but the dedication has paid off! please give
curryMulti
a round of applause! and don't forget that currying a diverse variety of types all at once brings strength!now that introductions are over: curryMulti behaves very much like curry, the only difference being that you can bind an arbitrary number of arguments to the curried
fn
function, instead of just a single argument at a time (like in the case of curry).