{"version":3,"file":"compose.mjs","names":[],"sources":["../../src/function/compose.ts"],"sourcesContent":["/**\n * Creates a function that is the composition of the provided functions,\n * where each successive invocation is supplied the return value of the previous.\n * Functions are executed from right to left.\n *\n * @param funcs - The functions to compose\n * @returns Returns the new composite function\n *\n * @example\n * const add = (x: number) => x + 1;\n * const multiply = (x: number) => x * 2;\n * const composed = compose(add, multiply);\n * composed(5); // => 11 (multiply(5) = 10, then add(10) = 11)\n *\n * @example\n * const toUpper = (str: string) => str.toUpperCase();\n * const exclaim = (str: string) => `${str}!`;\n * const shout = compose(exclaim, toUpper);\n * shout('hello'); // => 'HELLO!'\n */\nexport function compose<T>(...funcs: Array<(arg: T) => T>): (arg: T) => T {\n  if (funcs.length === 0) {\n    return (arg: T) => arg;\n  }\n\n  if (funcs.length === 1) {\n    return funcs[0];\n  }\n\n  return function composed(arg: T): T {\n    let result = arg;\n    for (let i = funcs.length - 1; i >= 0; i--) {\n      result = funcs[i](result);\n    }\n    return result;\n  };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,QAAW,GAAG,OAA4C;CACxE,IAAI,MAAM,WAAW,GACnB,QAAQ,QAAW;CAGrB,IAAI,MAAM,WAAW,GACnB,OAAO,MAAM;CAGf,OAAO,SAAS,SAAS,KAAW;EAClC,IAAI,SAAS;EACb,KAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KACrC,SAAS,MAAM,EAAE,CAAC,MAAM;EAE1B,OAAO;CACT;AACF"}