UNPKG

typedash

Version:

modern, type-safe collection of utility functions

1 lines 865 B
{"version":3,"sources":["../../src/functions/negate/negate.ts"],"names":[],"mappings":";AAcO,SAAS,OACd,MACwC;AACxC,SAAO,IAAI,SAA2B;AACpC,UAAM,SAAS,KAAK,GAAG,IAAI;AAC3B,WAAO,CAAC;AAAA,EACV;AACF","sourcesContent":["import { AnyFunction } from '../../types/_internal';\n\n/**\n * Returns a new function that negates the result of the input function.\n * @param func The input function to negate.\n * @returns A new function that negates the result of the input function.\n * @example\n * ```ts\n * const isEven = (num: number) => num % 2 === 0;\n * const isOdd = negate(isEven);\n * isOdd(1); // true\n * isOdd(2); // false\n * ```\n */\nexport function negate<Func extends AnyFunction<boolean>>(\n func: Func\n): (...args: Parameters<Func>) => boolean {\n return (...args: Parameters<Func>) => {\n const result = func(...args);\n return !result;\n };\n}\n"]}