UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

29 lines (27 loc) 743 B
import { dfdlT } from "@monstermann/dfdl"; import { cloneSet } from "@monstermann/remmi"; //#region src/set/compact.ts /** * `compact(target)` * * Removes all nullable values (`null` and `undefined`) from the `target` set and returns a new set. * * ```ts * compact(new Set([1, null, 2, undefined])); // Set([1, 2]) * compact(new Set([1, 2, 3])); // Set([1, 2, 3]) * ``` * * ```ts * pipe(new Set([1, null, 2, undefined]), compact()); // Set([1, 2]) * pipe(new Set([1, 2, 3]), compact()); // Set([1, 2, 3]) * ``` */ const compact = dfdlT((target) => { if (!target.has(null) && !target.has(void 0)) return target; target = cloneSet(target); target.delete(null); target.delete(void 0); return target; }, 1); //#endregion export { compact };