UNPKG

remeda

Version:

A utility library for JavaScript and Typescript.

1 lines 1.9 kB
{"version":3,"file":"doNothing.cjs","names":[],"sources":["../src/doNothing.ts"],"sourcesContent":["/**\n * A function that takes any arguments and does nothing with them. This is\n * useful as a placeholder for any function or API that requires a **void**\n * function (a function that doesn't return a value). This could also be used in\n * combination with a ternary or other conditional execution to allow disabling\n * a function call for a specific case.\n *\n * Notice that this is a dataLast impl where the function needs to be invoked\n * to get the \"do nothing\" function.\n *\n * See also:\n * * `constant` - A function that ignores it's arguments and returns the same value on every invocation.\n * * `identity` - A function that returns the first argument it receives.\n *\n * @signature\n * R.doNothing();\n * @example\n * myApi({ onSuccess: handleSuccess, onError: R.doNothing() });\n * myApi({ onSuccess: isDemoMode ? R.doNothing(): handleSuccess });\n * @dataLast\n * @category Function\n */\nexport function doNothing(): typeof doesNothing {\n // Notice that the exported identity function is just the \"factory\" for the\n // function. We do it this way so that all \"Function\" utilities have a similar\n // API where the function is called, and not just used \"headless\". e.g.\n // `doNothing()` and not `doNothing`, just like the API for `constant(1)`.\n return doesNothing;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- There is no other way to make typescript infer the function arguments \"backwards\" in data-last invocations without the Args type parameter. @see: https://github.com/typescript-eslint/typescript-eslint/issues/9887\nfunction doesNothing<Args extends ReadonlyArray<unknown>>(\n ..._args: Args\n): void {\n /* do nothing */\n}\n"],"mappings":"AAsBA,SAAgB,GAAgC,CAK9C,OAAO,EAIT,SAAS,EACP,GAAG,EACG"}