{"version":3,"file":"once.mjs","names":[],"sources":["../../src/function/once.ts"],"sourcesContent":["/**\n * Creates a function that is restricted to invoking func once.\n * Repeat calls to the function return the value of the first invocation.\n *\n * @template T - The type of the function\n * @param func - The function to restrict\n * @returns Returns the new restricted function\n *\n * @example\n * let count = 0;\n * const initialize = once(() => ++count);\n * initialize(); // => 1\n * initialize(); // => 1\n * console.log(count); // => 1\n *\n * @example\n * const greet = once((name: string) => `Hello, ${name}!`);\n * greet('Alice'); // => 'Hello, Alice!'\n * greet('Bob'); // => 'Hello, Alice!' (returns cached result)\n */\nexport function once<T extends (...args: never[]) => unknown>(func: T): T {\n  let called = false;\n  let result: ReturnType<T> | undefined;\n\n  return function (this: unknown, ...args: Parameters<T>): ReturnType<T> {\n    if (!called) {\n      called = true;\n      result = (func as (this: unknown, ...args: Parameters<T>) => ReturnType<T>).apply(this, args);\n    }\n    return result as ReturnType<T>;\n  } as T;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,KAA8C,MAAY;CACxE,IAAI,SAAS;CACb,IAAI;CAEJ,OAAO,SAAyB,GAAG,MAAoC;EACrE,IAAI,CAAC,QAAQ;GACX,SAAS;GACT,SAAU,KAAkE,MAAM,MAAM,IAAI;EAC9F;EACA,OAAO;CACT;AACF"}