UNPKG

remeda

Version:

A utility library for JavaScript and Typescript.

1 lines 2.34 kB
{"version":3,"file":"differenceWith.cjs","names":["purryFromLazy","SKIP_ITEM"],"sources":["../src/differenceWith.ts"],"sourcesContent":["import { purryFromLazy } from \"./internal/purryFromLazy\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { SKIP_ITEM } from \"./internal/utilityEvaluators\";\n\ntype IsEqual<T, Other> = (data: T, other: Other) => boolean;\n\n/**\n * Excludes the values from `other` array.\n * Elements are compared by custom comparator isEquals.\n *\n * @param data - The source array.\n * @param other - The values to exclude.\n * @param isEqual - The comparator.\n * @signature\n * R.differenceWith(data, other, isEqual)\n * @example\n * R.differenceWith(\n * [{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }],\n * [2, 5, 3],\n * ({ a }, b) => a === b,\n * ); //=> [{ a: 1 }, { a: 4 }]\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function differenceWith<T, Other>(\n data: ReadonlyArray<T>,\n other: ReadonlyArray<Other>,\n isEqual: IsEqual<T, Other>,\n): Array<T>;\n\n/**\n * Excludes the values from `other` array.\n * Elements are compared by custom comparator isEquals.\n *\n * @param other - The values to exclude.\n * @param isEqual - The comparator.\n * @signature\n * R.differenceWith(other, isEqual)(data)\n * @example\n * R.pipe(\n * [{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }, { a: 5 }, { a: 6 }],\n * R.differenceWith([2, 3], ({ a }, b) => a === b),\n * ); //=> [{ a: 1 }, { a: 4 }, { a: 5 }, { a: 6 }]\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function differenceWith<T, Other>(\n other: ReadonlyArray<Other>,\n isEqual: IsEqual<T, Other>,\n): (data: ReadonlyArray<T>) => Array<T>;\n\nexport function differenceWith(...args: ReadonlyArray<unknown>): unknown {\n return purryFromLazy(lazyImplementation, args);\n}\n\nconst lazyImplementation =\n <T, Other>(\n other: ReadonlyArray<Other>,\n isEqual: IsEqual<T, Other>,\n ): LazyEvaluator<T> =>\n (value) =>\n other.every((otherValue) => !isEqual(value, otherValue))\n ? { done: false, hasNext: true, next: value }\n : SKIP_ITEM;\n"],"mappings":"8FAqDA,SAAgB,EAAe,GAAG,EAAuC,CACvE,OAAOA,EAAAA,EAAc,EAAoB,EAAK,CAGhD,MAAM,GAEF,EACA,IAED,GACC,EAAM,MAAO,GAAe,CAAC,EAAQ,EAAO,EAAW,CAAC,CACpD,CAAE,KAAM,GAAO,QAAS,GAAM,KAAM,EAAO,CAC3CC,EAAAA"}