{"version":3,"file":"curry.mjs","sources":["../src/curry.ts"],"sourcesContent":["import type {\n  CurriedFunction1,\n  CurriedFunction2,\n  CurriedFunction3,\n  CurriedFunction4,\n  CurriedFunction5,\n} from 'lodash';\n\ntype AnyFunction = (...args: any[]) => any;\n\n// Same call signatures as lodash's `curry`, returning lodash's curried types, so the\n// declarations of everything curried with it are unchanged.\ninterface Curry {\n  <T1, R>(fn: (t1: T1) => R, arity?: number): CurriedFunction1<T1, R>;\n  <T1, T2, R>(fn: (t1: T1, t2: T2) => R, arity?: number): CurriedFunction2<T1, T2, R>;\n  <T1, T2, T3, R>(\n    fn: (t1: T1, t2: T2, t3: T3) => R,\n    arity?: number\n  ): CurriedFunction3<T1, T2, T3, R>;\n  <T1, T2, T3, T4, R>(\n    fn: (t1: T1, t2: T2, t3: T3, t4: T4) => R,\n    arity?: number\n  ): CurriedFunction4<T1, T2, T3, T4, R>;\n  <T1, T2, T3, T4, T5, R>(\n    fn: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5) => R,\n    arity?: number\n  ): CurriedFunction5<T1, T2, T3, T4, T5, R>;\n  (fn: AnyFunction, arity?: number): AnyFunction;\n}\n\n/**\n * Curries `fn` by closing over the arguments supplied so far.\n *\n * Used instead of lodash `curry` for functions that are partially applied on every\n * request, such as the query traversals (`traverseQueryPopulate(visitor, ctx)`). On every\n * partial call lodash builds a new wrapper and derives its `toString` by stringifying the\n * whole source of the curried function and running regexes over it, which showed up as a\n * significant share of request CPU.\n *\n * Behaves like lodash `curry` otherwise: `fn` is called as soon as at least `arity`\n * arguments have been supplied (any extra ones are passed along), and `arity` defaults to\n * `fn.length`. Placeholders are not supported.\n */\nexport const curry: Curry = (fn: AnyFunction, arity: number = fn.length): AnyFunction => {\n  const curried: AnyFunction = (...args) => {\n    if (args.length >= arity) {\n      return fn(...args);\n    }\n\n    return (...rest: unknown[]) => curried(...args, ...rest);\n  };\n\n  return curried;\n};\n"],"names":["curry","fn","arity","length","curried","args","rest"],"mappings":"AA8BA;;;;;;;;;;;;AAYC,IACM,MAAMA,KAAAA,GAAe,CAACC,EAAAA,EAAiBC,KAAAA,GAAgBD,GAAGE,MAAM,GAAA;IACrE,MAAMC,OAAAA,GAAuB,CAAC,GAAGC,IAAAA,GAAAA;QAC/B,IAAIA,IAAAA,CAAKF,MAAM,IAAID,KAAAA,EAAO;AACxB,YAAA,OAAOD,EAAAA,CAAAA,GAAMI,IAAAA,CAAAA;AACf,QAAA;AAEA,QAAA,OAAO,CAAC,GAAGC,IAAAA,GAAoBF,OAAAA,CAAAA,GAAWC,IAAAA,EAAAA,GAASC,IAAAA,CAAAA;AACrD,IAAA,CAAA;IAEA,OAAOF,OAAAA;AACT;;;;"}