remeda
Version:
A utility library for JavaScript and Typescript.
1 lines • 781 B
Source Map (JSON)
{"version":3,"file":"once.cjs","names":["ret: T"],"sources":["../src/once.ts"],"sourcesContent":["/**\n * Creates a function that is restricted to invoking `func` once. Repeat calls to the function return the value of the first invocation.\n *\n * @param fn - The function to wrap.\n * @signature R.once(fn)\n * @example\n * const initialize = R.once(createApplication);\n * initialize();\n * initialize();\n * // => `createApplication` is invoked once\n * @category Function\n */\nexport function once<T>(fn: () => T): () => T {\n let called = false;\n let ret: T;\n return () => {\n if (!called) {\n ret = fn();\n called = true;\n }\n return ret;\n };\n}\n"],"mappings":"AAYA,SAAgB,EAAQ,EAAsB,CAC5C,IAAI,EAAS,GACTA,EACJ,WACE,AAEE,KADA,EAAM,GAAI,CACD,IAEJ"}