ts-data-forge 14.0.1 → 14.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +5 -5
  2. package/dist/array/impl/array-utils-transformation.d.mts +4 -1
  3. package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
  4. package/dist/array/impl/array-utils-transformation.mjs +4 -5
  5. package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
  6. package/dist/array/impl/array-utils-validation.d.mts +8 -3
  7. package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
  8. package/dist/array/impl/array-utils-validation.mjs.map +1 -1
  9. package/dist/collections/imap-mapped.mjs +1 -1
  10. package/dist/collections/imap-mapped.mjs.map +1 -1
  11. package/dist/collections/imap.mjs +1 -1
  12. package/dist/collections/imap.mjs.map +1 -1
  13. package/dist/functional/match.d.mts.map +1 -1
  14. package/dist/functional/match.mjs.map +1 -1
  15. package/dist/number/branded-types/int.d.mts +1 -1
  16. package/dist/number/branded-types/int16.d.mts +1 -1
  17. package/dist/number/branded-types/int32.d.mts +1 -1
  18. package/dist/number/branded-types/non-negative-int16.d.mts +1 -1
  19. package/dist/number/branded-types/non-negative-int32.d.mts +1 -1
  20. package/dist/number/branded-types/non-positive-finite-number.mjs +1 -1
  21. package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
  22. package/dist/number/branded-types/positive-int.d.mts +1 -1
  23. package/dist/number/branded-types/positive-int16.d.mts +1 -1
  24. package/dist/number/branded-types/positive-int32.d.mts +1 -1
  25. package/dist/number/branded-types/positive-safe-int.d.mts +1 -1
  26. package/dist/number/branded-types/positive-uint16.d.mts +1 -1
  27. package/dist/number/branded-types/positive-uint32.d.mts +1 -1
  28. package/dist/number/branded-types/safe-int.d.mts +1 -1
  29. package/dist/number/branded-types/safe-uint.d.mts +1 -1
  30. package/dist/number/branded-types/uint.d.mts +1 -1
  31. package/dist/number/branded-types/uint16.d.mts +1 -1
  32. package/dist/number/branded-types/uint32.d.mts +1 -1
  33. package/dist/number/enum/int8.d.mts +2 -2
  34. package/dist/number/enum/int8.d.mts.map +1 -1
  35. package/dist/number/enum/int8.mjs.map +1 -1
  36. package/dist/number/enum/uint8.d.mts +2 -2
  37. package/dist/number/enum/uint8.d.mts.map +1 -1
  38. package/dist/number/enum/uint8.mjs.map +1 -1
  39. package/dist/number/num-arithmetic-types.d.mts +8 -9
  40. package/dist/number/num-arithmetic-types.d.mts.map +1 -1
  41. package/dist/number/refined-number-utils.d.mts +2 -2
  42. package/dist/number/refined-number-utils.d.mts.map +1 -1
  43. package/dist/number/refined-number-utils.mjs.map +1 -1
  44. package/dist/object/object.d.mts +12 -12
  45. package/dist/object/object.d.mts.map +1 -1
  46. package/dist/object/object.mjs +5 -1
  47. package/dist/object/object.mjs.map +1 -1
  48. package/dist/others/fast-deep-equal.d.mts.map +1 -1
  49. package/dist/others/fast-deep-equal.mjs +2 -2
  50. package/dist/others/fast-deep-equal.mjs.map +1 -1
  51. package/package.json +2 -2
  52. package/src/array/impl/array-utils-modification.test.mts +26 -5
  53. package/src/array/impl/array-utils-shape-invariants.test.mts +259 -17
  54. package/src/array/impl/array-utils-slicing.test.mts +11 -3
  55. package/src/array/impl/array-utils-transformation.mts +41 -18
  56. package/src/array/impl/array-utils-transformation.test.mts +10 -3
  57. package/src/array/impl/array-utils-validation.mts +54 -10
  58. package/src/array/impl/array-utils-validation.test.mts +153 -3
  59. package/src/collections/imap-mapped.mts +1 -1
  60. package/src/collections/imap-mapped.test.mts +2 -2
  61. package/src/collections/imap.mts +1 -1
  62. package/src/collections/iset-mapped.test.mts +1 -1
  63. package/src/functional/match.mts +5 -4
  64. package/src/functional/result.test.mts +5 -2
  65. package/src/guard/is-primitive.test.mts +1 -1
  66. package/src/guard/is-record.test.mts +4 -4
  67. package/src/guard/is-type.test.mts +2 -2
  68. package/src/number/branded-types/finite-number.test.mts +2 -2
  69. package/src/number/branded-types/non-negative-finite-number.test.mts +2 -2
  70. package/src/number/branded-types/non-positive-finite-number.mts +1 -1
  71. package/src/number/branded-types/non-positive-finite-number.test.mts +5 -9
  72. package/src/number/branded-types/non-zero-finite-number.test.mts +2 -2
  73. package/src/number/branded-types/positive-finite-number.test.mts +2 -2
  74. package/src/number/enum/int8.mts +2 -1
  75. package/src/number/enum/uint8.mts +6 -2
  76. package/src/number/num-arithmetic-types.mts +125 -24
  77. package/src/number/num.test.mts +9 -9
  78. package/src/number/refined-number-utils.mts +2 -1
  79. package/src/object/object.mts +29 -17
  80. package/src/object/object.test.mts +2 -1
  81. package/src/others/fast-deep-equal.mts +6 -4
@@ -1 +1 @@
1
- {"version":3,"file":"imap-mapped.mjs","sources":["../../src/collections/imap-mapped.mts"],"sourcesContent":["/* eslint-disable unicorn/prefer-iterator-to-array-at-end */\nimport { type WidenLiteral } from 'ts-type-forge';\nimport { Optional, pipe } from '../functional/index.mjs';\nimport { asUint32 } from '../number/index.mjs';\nimport { tp } from '../others/index.mjs';\nimport { type MapSetKeyType, type SizeType } from '../types.mjs';\n\n/**\n * Interface for an immutable map with custom key mapping and lookup operations.\n *\n * IMapMapped allows you to use complex objects as keys by providing\n * transformation functions that convert between your custom key type `K` and a\n * primitive `MapSetKeyType` `KM` that can be efficiently stored in JavaScript's\n * native Map. This enables operations on maps with complex keys while\n * maintaining type safety and immutability.\n *\n * **Key Features:**\n *\n * - **Custom Key Types**: Use any type as keys by providing `toKey`/`fromKey`\n * functions\n * - **Immutable**: All operations return new instances, preserving immutability\n * - **Type Safe**: Full TypeScript support with generic key/value types\n *\n * **Performance Characteristics:**\n *\n * - get/has: O(1) average case (plus key transformation overhead)\n * - set/delete: O(n) due to copying for immutability (plus key transformation\n * overhead)\n * - map/filter operations: O(n)\n * - iteration: O(n) (plus key transformation overhead)\n *\n * @template K The type of the custom keys in the map.\n * @template V The type of the values in the map.\n * @template KM The type of the mapped primitive keys (string, number, etc.).\n */\ntype IMapMappedInterface<K, V, KM extends MapSetKeyType> = Readonly<{\n // Getting information\n\n /**\n * The number of elements in the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * assert.isTrue(map.size === 2);\n * ```\n */\n size: SizeType.Arr;\n\n /**\n * Checks if a key exists in the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [[{ x: 1, y: 2 }, 'A']],\n * toKey,\n * fromKey,\n * );\n *\n * assert.isTrue(map.has({ x: 1, y: 2 }));\n *\n * assert.isFalse(map.has({ x: 3, y: 4 }));\n * ```\n *\n * @param key The key to check.\n * @returns `true` if the key exists, `false` otherwise.\n */\n has: (key: K | (WidenLiteral<K> & {})) => boolean;\n\n /**\n * Retrieves the value associated with a key.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [[{ x: 1, y: 2 }, 'A']],\n * toKey,\n * fromKey,\n * );\n *\n * assert.deepStrictEqual(map.get({ x: 1, y: 2 }), Optional.some('A'));\n *\n * assert.deepStrictEqual(map.get({ x: 0, y: 0 }), Optional.none);\n * ```\n *\n * @param key The key to retrieve.\n * @returns The value associated with the key wrapped with `Optional.some`, or\n * `Optional.none` if the key does not exist.\n */\n get: (key: K | (WidenLiteral<K> & {})) => Optional<V>;\n\n // Reducing a value\n\n /**\n * Checks if all elements in the map satisfy a predicate. Also supports a\n * type predicate overload that narrows the type of values in the map if the\n * predicate returns true for all elements.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, number, string>(\n * [\n * [{ x: 0, y: 0 }, 2],\n * [{ x: 1, y: 0 }, 4],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const allEven = map.every((value) => value % 2 === 0);\n *\n * const isNarrowed = map.every((value): value is 2 | 4 => value % 2 === 0);\n *\n * assert.isTrue(allEven);\n *\n * assert.isTrue(isNarrowed);\n * ```\n *\n * @template W The narrowed type of the values.\n * @param predicate A function to test each key-value pair.\n * @returns `true` if all elements satisfy the predicate, `false` otherwise.\n */\n every: ((predicate: (value: V, key: K) => boolean) => boolean) &\n (<W extends V>(\n predicate: (value: V, key: K) => value is W,\n ) => this is IMapMapped<K, W, KM>);\n\n /**\n * Checks if at least one element in the map satisfies a predicate.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, number, string>(\n * [\n * [{ x: 0, y: 0 }, 3],\n * [{ x: 1, y: 0 }, 7],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * assert.isTrue(map.some((value) => value > 5));\n *\n * assert.isFalse(map.some((value) => value > 10));\n * ```\n *\n * @param predicate A function to test each key-value pair.\n * @returns `true` if at least one element satisfies the predicate, `false`\n * otherwise.\n */\n some: (predicate: (value: V, key: K) => boolean) => boolean;\n\n // Mutation\n\n /**\n * Deletes a key-value pair from the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const original = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const withoutRight = original.delete({ x: 1, y: 0 });\n *\n * assert.deepStrictEqual(\n * original.get({ x: 1, y: 0 }),\n * Optional.some('right'),\n * );\n *\n * assert.deepStrictEqual(withoutRight.get({ x: 1, y: 0 }), Optional.none);\n *\n * assert.isTrue(original.size === 2);\n *\n * assert.isTrue(withoutRight.size === 1);\n * ```\n *\n * @param key The key to delete.\n * @returns A new IMapMapped instance without the specified key.\n */\n delete: (key: K) => IMapMapped<K, V, KM>;\n\n /**\n * Sets a key-value pair in the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const base = IMapMapped.create<Point, string, string>(\n * [[{ x: 0, y: 0 }, 'origin']],\n * toKey,\n * fromKey,\n * );\n *\n * const updated = base.set({ x: 0, y: 0 }, 'home');\n *\n * const extended = base.set({ x: 1, y: 0 }, 'right');\n *\n * assert.deepStrictEqual(base.get({ x: 0, y: 0 }), Optional.some('origin'));\n *\n * assert.deepStrictEqual(updated.get({ x: 0, y: 0 }), Optional.some('home'));\n *\n * assert.deepStrictEqual(\n * extended.get({ x: 1, y: 0 }),\n * Optional.some('right'),\n * );\n * ```\n *\n * @param key The key to set.\n * @param value The value to associate with the key.\n * @returns A new IMapMapped instance with the specified key-value pair.\n */\n set: (key: K, value: V) => IMapMapped<K, V, KM>;\n\n /**\n * Updates the value associated with a key using an updater function.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const scores = IMapMapped.create<Point, number, string>(\n * [\n * [{ x: 0, y: 0 }, 10],\n * [{ x: 1, y: 0 }, 8],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const boosted = scores.update({ x: 0, y: 0 }, (value) => value + 5);\n *\n * const unchanged = scores.update({ x: 9, y: 9 }, (value) => value + 1);\n *\n * assert.deepStrictEqual(boosted.get({ x: 0, y: 0 }), Optional.some(15));\n *\n * assert.deepStrictEqual(scores.get({ x: 0, y: 0 }), Optional.some(10));\n *\n * assert.isTrue(unchanged === scores);\n * ```\n *\n * @param key The key whose value to update.\n * @param updater A function that takes the current value and returns the new\n * value.\n * @returns A new IMapMapped instance with the updated value.\n */\n update: (key: K, updater: (value: V) => V) => IMapMapped<K, V, KM>;\n\n /**\n * Applies a series of mutations to the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const base = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const mutated = base.withMutations([\n * { type: 'set', key: { x: 2, y: 0 }, value: 'far' },\n * { type: 'update', key: { x: 1, y: 0 }, updater: (v) => v.toUpperCase() },\n * { type: 'delete', key: { x: 0, y: 0 } },\n * ]);\n *\n * assert.deepStrictEqual(mutated.get({ x: 2, y: 0 }), Optional.some('far'));\n *\n * assert.deepStrictEqual(mutated.get({ x: 1, y: 0 }), Optional.some('RIGHT'));\n *\n * assert.deepStrictEqual(mutated.get({ x: 0, y: 0 }), Optional.none);\n *\n * assert.deepStrictEqual(base.get({ x: 1, y: 0 }), Optional.some('right'));\n * ```\n *\n * @param actions An array of mutation actions (delete, set, or update).\n * @returns A new IMapMapped instance with all mutations applied.\n */\n withMutations: (\n actions: readonly Readonly<\n | { type: 'delete'; key: K }\n | { type: 'set'; key: K; value: V }\n | { type: 'update'; key: K; updater: (value: V) => V }\n >[],\n ) => IMapMapped<K, V, KM>;\n\n // Sequence algorithms\n\n /**\n * Maps the values of the map to new values.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, number, string>(\n * [\n * [{ x: 0, y: 0 }, 1],\n * [{ x: 1, y: 0 }, 2],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const doubled = map.map((value) => value * 2);\n *\n * assert.deepStrictEqual(Array.from(doubled), [\n * [{ x: 0, y: 0 }, 2],\n * [{ x: 1, y: 0 }, 4],\n * ]);\n * ```\n *\n * @template V2 The type of the new values.\n * @param mapFn A function that maps a value and key to a new value.\n * @returns A new IMapMapped instance with mapped values.\n */\n map: <V2>(mapFn: (value: V, key: K) => V2) => IMapMapped<K, V2, KM>;\n\n /**\n * Maps the keys of the map to new keys. Note: The key type cannot be changed\n * because `toKey` and `fromKey` would become unusable.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const shifted = map.mapKeys((p) => ({ x: p.x + 10, y: p.y + 10 }));\n *\n * assert.deepStrictEqual(Array.from(shifted), [\n * [{ x: 10, y: 10 }, 'origin'],\n * [{ x: 11, y: 10 }, 'right'],\n * ]);\n * ```\n *\n * @param mapFn A function that maps a key to a new key of the same type.\n * @returns A new IMapMapped instance with mapped keys.\n */\n mapKeys: (mapFn: (key: K) => K) => IMapMapped<K, V, KM>;\n\n /**\n * Maps the entries (key-value pairs) of the map to new entries.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, number, string>(\n * [\n * [{ x: 0, y: 0 }, 1],\n * [{ x: 1, y: 0 }, 2],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const labeled = map.mapEntries(([key, value]) => [key, `value=${value}`]);\n *\n * assert.deepStrictEqual(Array.from(labeled), [\n * [{ x: 0, y: 0 }, 'value=1'],\n * [{ x: 1, y: 0 }, 'value=2'],\n * ]);\n * ```\n *\n * @template V2 The type of the new values in the entries.\n * @param mapFn A function that maps an entry to a new entry (key must remain\n * the same type).\n * @returns A new IMapMapped instance with mapped entries.\n */\n mapEntries: <V2>(\n mapFn: (entry: readonly [K, V]) => readonly [K, V2],\n ) => IMapMapped<K, V2, KM>;\n\n // Side effects\n\n /**\n * Executes a callback function for each key-value pair in the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const mut_entries: (readonly [Point, string])[] = [];\n *\n * map.forEach((value, key) => {\n * mut_entries.push([key, value]);\n * });\n *\n * assert.deepStrictEqual(mut_entries, [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ]);\n * ```\n *\n * @param callbackfn A function to execute for each element.\n */\n forEach: (callbackfn: (value: V, key: K) => void) => void;\n\n // Iterators\n\n /**\n * Returns an iterator for the keys in the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const keys = Array.from(map.keys());\n *\n * assert.deepStrictEqual(keys, [\n * { x: 0, y: 0 },\n * { x: 1, y: 0 },\n * ]);\n * ```\n *\n * @returns An iterable iterator of keys.\n */\n keys: () => IterableIterator<K>;\n\n /**\n * Returns an iterator for the values in the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const values = Array.from(map.values());\n *\n * assert.deepStrictEqual(values, ['origin', 'right']);\n * ```\n *\n * @returns An iterable iterator of values.\n */\n values: () => IterableIterator<V>;\n\n /**\n * Returns an iterator for the entries (key-value pairs) in the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const entries = Array.from(map.entries());\n *\n * assert.deepStrictEqual(entries, [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ]);\n * ```\n *\n * @returns An iterable iterator of entries.\n */\n entries: () => IterableIterator<readonly [K, V]>;\n\n // Conversion\n\n /**\n * Converts the keys of the map to an array.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * assert.deepStrictEqual(map.toKeysArray(), [\n * { x: 0, y: 0 },\n * { x: 1, y: 0 },\n * ]);\n * ```\n *\n * @returns A readonly array of keys.\n */\n toKeysArray: () => readonly K[];\n\n /**\n * Converts the values of the map to an array.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * assert.deepStrictEqual(map.toValuesArray(), ['origin', 'right']);\n * ```\n *\n * @returns A readonly array of values.\n */\n toValuesArray: () => readonly V[];\n\n /**\n * Converts the entries (key-value pairs) of the map to an array.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * assert.deepStrictEqual(map.toEntriesArray(), [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ]);\n * ```\n *\n * @returns A readonly array of entries.\n */\n toEntriesArray: () => readonly (readonly [K, V])[];\n\n /**\n * Converts the map to an array of entries (key-value pairs). Alias for\n * `toEntriesArray`.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * assert.deepStrictEqual(map.toArray(), [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ]);\n * ```\n *\n * @returns A readonly array of entries.\n */\n toArray: () => readonly (readonly [K, V])[];\n\n /**\n * Returns the underlying readonly JavaScript Map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [[{ x: 1, y: 2 }, 'A']],\n * toKey,\n * fromKey,\n * );\n *\n * const raw = map.toRawMap();\n *\n * assert.isTrue(isMap(raw));\n *\n * assert.isTrue(raw.get(toKey({ x: 1, y: 2 })) === 'A');\n * ```\n *\n * @returns The raw ReadonlyMap instance.\n */\n toRawMap: () => ReadonlyMap<KM, V>;\n}>;\n\n/**\n * Represents an immutable map with custom key transformation and\n * high-performance operations.\n *\n * IMapMapped is a specialized persistent data structure that enables using\n * complex objects as map keys while maintaining the performance benefits of\n * JavaScript's native Map. It achieves this by requiring bidirectional\n * transformation functions that convert between your custom key type and a\n * primitive type that can be efficiently stored and compared.\n *\n * **Key Features:**\n *\n * - **Complex Keys**: Use objects, arrays, or any custom type as map keys\n * - **Immutable**: All mutation operations return new instances\n * - **Type Safe**: Full TypeScript support with compile-time key/value type\n * checking\n * - **Bidirectional**: Maintains ability to reconstruct original keys from mapped\n * keys\n *\n * **Use Cases:**\n *\n * - Maps with composite keys (e.g., coordinates, user IDs with metadata)\n * - Caching with complex cache keys\n * - State management where entities have multi-part identifiers\n * - Performance-critical maps with non-primitive keys\n *\n * @template K The type of the custom keys in the map.\n * @template V The type of the values in the map.\n * @template KM The type of the mapped primitive keys (string, number, etc.).\n */\nexport type IMapMapped<K, V, KM extends MapSetKeyType> = Iterable<\n readonly [K, V]\n> &\n IMapMappedInterface<K, V, KM>;\n\n/** Provides utility functions for IMapMapped. */\nexport namespace IMapMapped {\n /**\n * Creates a new IMapMapped instance with custom key transformation functions.\n *\n * This factory function creates an immutable map that can use complex objects\n * as keys by providing bidirectional transformation functions. The `toKey`\n * function converts your custom key type to a primitive type that can be\n * efficiently stored, while `fromKey` reconstructs the original key type for\n * iteration and access.\n *\n * **Performance:** O(n) where n is the number of entries in the iterable.\n *\n * @template K The type of the custom keys.\n * @template V The type of the values.\n * @template KM The type of the mapped primitive keys.\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * assert.isTrue(map.size === 2);\n *\n * assert.deepStrictEqual(map.get({ x: 0, y: 0 }), Optional.some('origin'));\n * ```\n *\n * @param iterable An iterable of key-value pairs using the custom key type.\n * @param toKey A function that converts a custom key `K` to a primitive key\n * `KM`. This function must be deterministic and produce unique values for\n * unique keys.\n * @param fromKey A function that converts a primitive key `KM` back to the\n * custom key `K`. This should be the inverse of `toKey`.\n * @returns A new IMapMapped instance containing all entries from the\n * iterable.\n */\n export const create = <K, V, KM extends MapSetKeyType>(\n iterable: Iterable<readonly [K, V]>,\n toKey: (a: K) => KM,\n fromKey: (k: KM) => K,\n ): IMapMapped<K, V, KM> =>\n new IMapMappedClass<K, V, KM>(iterable, toKey, fromKey);\n\n /**\n * Checks if two IMapMapped instances are structurally equal.\n *\n * Two IMapMapped instances are considered equal if they have the same size\n * and contain exactly the same key-value pairs. The comparison is performed\n * on the underlying mapped keys and values, so the transformation functions\n * themselves don't need to be identical. Values are compared using\n * JavaScript's `===` operator.\n *\n * **Performance:** O(n) where n is the size of the smaller map.\n *\n * @template K The type of the custom keys.\n * @template V The type of the values.\n * @template KM The type of the mapped primitive keys.\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const first = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const second = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 1, y: 0 }, 'right'],\n * [{ x: 0, y: 0 }, 'origin'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const third = IMapMapped.create<Point, string, string>(\n * [[{ x: 0, y: 0 }, 'different']],\n * toKey,\n * fromKey,\n * );\n *\n * assert.isTrue(IMapMapped.equal(first, second));\n *\n * assert.isFalse(IMapMapped.equal(first, third));\n * ```\n *\n * @param a The first IMapMapped instance to compare.\n * @param b The second IMapMapped instance to compare.\n * @returns `true` if the maps contain exactly the same key-value pairs,\n * `false` otherwise.\n */\n export const equal = <K, V, KM extends MapSetKeyType>(\n a: IMapMapped<K, V, KM>,\n b: IMapMapped<K, V, KM>,\n ): boolean =>\n a.size === b.size &&\n a.every(\n (v, k) =>\n pipe(b.get(k)).map((bv) => Optional.isSome(bv) && bv.value === v).value,\n );\n}\n\n/**\n * Internal class implementation for IMapMapped providing immutable map\n * operations with key transformation.\n *\n * This class implements the IMapMapped interface by maintaining a JavaScript\n * Map with primitive keys internally while exposing an API that works with\n * custom key types. The transformation between custom and primitive keys is\n * handled transparently through the provided `toKey` and `fromKey` functions.\n *\n * **Implementation Details:**\n *\n * - Uses ReadonlyMap<KM, V> internally where KM is the primitive key type\n * - Stores transformation functions for bidirectional key conversion\n * - Implements copy-on-write semantics for efficiency\n * - Provides optional debug messaging for development\n *\n * @template K The type of the custom keys.\n * @template V The type of the values.\n * @template KM The type of the mapped primitive keys.\n * @implements IMapMapped\n * @implements Iterable\n * @internal This class should not be used directly. Use IMapMapped.create() instead.\n */\nclass IMapMappedClass<K, V, KM extends MapSetKeyType>\n implements IMapMapped<K, V, KM>, Iterable<readonly [K, V]>\n{\n readonly #map: ReadonlyMap<KM, V>;\n readonly #toKey: (a: K) => KM;\n readonly #fromKey: (k: KM) => K;\n readonly #showNotFoundMessage: boolean;\n\n /**\n * Constructs an IMapMappedClass instance with custom key transformation.\n *\n * @param iterable An iterable of key-value pairs using the custom key type K.\n * @param toKey A function that converts a custom key K to a primitive key KM.\n * Must be deterministic and produce unique values for unique keys.\n * @param fromKey A function that converts a primitive key KM back to the\n * custom key K. Should be the inverse of the toKey function.\n * @param showNotFoundMessage Whether to log warning messages when operations\n * are performed on non-existent keys. Useful for debugging. Defaults to\n * false for production use.\n * @internal Use IMapMapped.create() instead of calling this constructor directly.\n */\n constructor(\n iterable: Iterable<readonly [K, V]>,\n toKey: (a: K) => KM,\n fromKey: (k: KM) => K,\n showNotFoundMessage: boolean = false,\n ) {\n this.#map = new Map(Array.from(iterable, ([k, v]) => [toKey(k), v]));\n\n this.#toKey = toKey;\n\n this.#fromKey = fromKey;\n\n this.#showNotFoundMessage = showNotFoundMessage;\n }\n\n /** @inheritdoc */\n get size(): SizeType.Arr {\n return asUint32(this.#map.size);\n }\n\n /** @inheritdoc */\n has(key: K | (WidenLiteral<K> & {})): boolean {\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return this.#map.has(this.#toKey(key as K));\n }\n\n /** @inheritdoc */\n get(key: K | (WidenLiteral<K> & {})): Optional<V> {\n if (!this.has(key)) return Optional.none;\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, total-functions/no-unsafe-type-assertion\n return Optional.some(this.#map.get(this.#toKey(key as K))!);\n }\n\n /** @inheritdoc */\n every<W extends V>(\n predicate: (value: V, key: K) => value is W,\n ): this is IMapMapped<K, W, KM>;\n\n /** @inheritdoc */\n every(predicate: (value: V, key: K) => boolean): boolean;\n\n /** @inheritdoc */\n every(predicate: (value: V, key: K) => boolean): boolean {\n for (const [k, v] of this.entries()) {\n if (!predicate(v, k)) return false;\n }\n\n return true;\n }\n\n /** @inheritdoc */\n some(predicate: (value: V, key: K) => boolean): boolean {\n for (const [k, v] of this.entries()) {\n if (predicate(v, k)) return true;\n }\n\n return false;\n }\n\n /** @inheritdoc */\n delete(key: K): IMapMapped<K, V, KM> {\n if (!this.has(key)) {\n if (this.#showNotFoundMessage) {\n console.warn(\n `IMapMapped.delete: key not found: ${String(this.#toKey(key))}`,\n );\n }\n\n return this;\n }\n\n const keyMapped = this.#toKey(key);\n\n return IMapMapped.create(\n Array.from(this.#map)\n .filter(([km]) => !Object.is(km, keyMapped))\n .map(([km, v]) => tp(this.#fromKey(km), v)),\n this.#toKey,\n this.#fromKey,\n );\n }\n\n /** @inheritdoc */\n set(key: K, value: V): IMapMapped<K, V, KM> {\n const curr = this.get(key);\n\n if (Optional.isSome(curr) && value === curr.value) return this;\n\n const keyMapped = this.#toKey(key);\n\n if (!this.has(key)) {\n return IMapMapped.create(\n [...this.#map, tp(keyMapped, value)].map(([km, v]) =>\n tp(this.#fromKey(km), v),\n ),\n this.#toKey,\n this.#fromKey,\n );\n }\n\n return IMapMapped.create(\n Array.from(this.#map, ([km, v]) =>\n tp(this.#fromKey(km), Object.is(km, keyMapped) ? value : v),\n ),\n this.#toKey,\n this.#fromKey,\n );\n }\n\n /** @inheritdoc */\n update(key: K, updater: (value: V) => V): IMapMapped<K, V, KM> {\n const curr = this.get(key);\n\n if (Optional.isNone(curr)) {\n if (this.#showNotFoundMessage) {\n console.warn(\n `IMapMapped.update: key not found: ${String(this.#toKey(key))}`,\n );\n }\n\n return this;\n }\n\n const keyMapped = this.#toKey(key);\n\n return IMapMapped.create(\n Array.from(this.#map, ([km, v]) =>\n tp(\n this.#fromKey(km),\n Object.is(km, keyMapped) ? updater(curr.value) : v,\n ),\n ),\n this.#toKey,\n this.#fromKey,\n );\n }\n\n /** @inheritdoc */\n withMutations(\n actions: readonly Readonly<\n | { type: 'delete'; key: K }\n | { type: 'set'; key: K; value: V }\n | { type: 'update'; key: K; updater: (value: V) => V }\n >[],\n ): IMapMapped<K, V, KM> {\n const mut_result = new Map<KM, V>(this.#map);\n\n const updateFn = (\n action: Readonly<\n | { type: 'delete'; key: K }\n | { type: 'set'; key: K; value: V }\n | { type: 'update'; key: K; updater: (value: V) => V }\n >,\n ): void => {\n const key = this.#toKey(action.key);\n\n switch (action.type) {\n case 'delete':\n mut_result.delete(key);\n\n break;\n\n case 'set':\n mut_result.set(key, action.value);\n\n break;\n\n case 'update': {\n const curr = mut_result.get(key);\n\n if (!mut_result.has(key) || curr === undefined) {\n if (this.#showNotFoundMessage) {\n console.warn(\n `IMapMapped.withMutations::update: key not found: ${String(key)}`,\n );\n }\n\n break;\n }\n\n mut_result.set(key, action.updater(curr));\n\n break;\n }\n }\n };\n\n for (const action of actions) {\n updateFn(action);\n }\n\n return IMapMapped.create<K, V, KM>(\n Array.from(mut_result, ([k, v]) => [this.#fromKey(k), v]),\n this.#toKey,\n this.#fromKey,\n );\n }\n\n /** @inheritdoc */\n map<V2>(mapFn: (value: V, key: K) => V2): IMapMapped<K, V2, KM> {\n return IMapMapped.create(\n this.toArray().map(([k, v]) => tp(k, mapFn(v, k))),\n this.#toKey,\n this.#fromKey,\n );\n }\n\n /** @inheritdoc */\n mapKeys(mapFn: (key: K) => K): IMapMapped<K, V, KM> {\n return IMapMapped.create(\n this.toArray().map(([k, v]) => tp(mapFn(k), v)),\n this.#toKey,\n this.#fromKey,\n );\n }\n\n /** @inheritdoc */\n mapEntries<V2>(\n mapFn: (entry: readonly [K, V]) => readonly [K, V2],\n ): IMapMapped<K, V2, KM> {\n return IMapMapped.create(\n this.toArray().map(mapFn),\n this.#toKey,\n this.#fromKey,\n );\n }\n\n /** @inheritdoc */\n forEach(callbackfn: (value: V, key: K) => void): void {\n for (const [km, value] of this.#map) {\n callbackfn(value, this.#fromKey(km));\n }\n }\n\n /**\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const collected = Array.from(map);\n *\n * assert.deepStrictEqual(collected, [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ]);\n * ```\n *\n * @inheritdoc\n */\n *[Symbol.iterator](): Iterator<readonly [K, V]> {\n for (const e of this.entries()) {\n yield e;\n }\n }\n\n /** @inheritdoc */\n *keys(): IterableIterator<K> {\n for (const km of this.#map.keys()) {\n yield this.#fromKey(km);\n }\n }\n\n /** @inheritdoc */\n values(): IterableIterator<V> {\n return this.#map.values();\n }\n\n /** @inheritdoc */\n *entries(): IterableIterator<readonly [K, V]> {\n for (const [km, v] of this.#map) {\n yield [this.#fromKey(km), v];\n }\n }\n\n /** @inheritdoc */\n toKeysArray(): readonly K[] {\n return Array.from(this.keys());\n }\n\n /** @inheritdoc */\n toValuesArray(): readonly V[] {\n return Array.from(this.values());\n }\n\n /** @inheritdoc */\n toEntriesArray(): readonly (readonly [K, V])[] {\n return Array.from(this.entries());\n }\n\n /** @inheritdoc */\n toArray(): readonly (readonly [K, V])[] {\n return Array.from(this.entries());\n }\n\n /** @inheritdoc */\n toRawMap(): ReadonlyMap<KM, V> {\n return this.#map;\n }\n}\n"],"names":["IMapMapped","Optional.isSome","Optional.none","Optional.some","Optional.isNone"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAozBO,IAAU;AAAA,CAAV,CAAUA,WAAAA,KAAV;AAgDE,EAAMA,WAAAA,CAAA,MAAA,GAAS,CACpB,QAAA,EACA,KAAA,EACA,YAEA,IAAI,eAAA,CAA0B,QAAA,EAAU,KAAA,EAAO,OAAO,CAAA;AA4DjD,EAAMA,WAAAA,CAAA,QAAQ,CACnB,CAAA,EACA,MAEA,CAAA,CAAE,IAAA,KAAS,CAAA,CAAE,IAAA,IACb,CAAA,CAAE,KAAA;AAAA,IACA,CAAC,CAAA,EAAG,CAAA,KACF,KAAK,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,CAAA,CAAE,IAAI,CAAC,EAAA,KAAOC,MAAS,CAAO,EAAE,KAAK,EAAA,CAAG,KAAA,KAAU,CAAC,CAAA,CAAE;AAAA,GACtE;AAAA,CAAA,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GAAG,CAAC,CAAA;AAAA,IAC7B;AAAA,EACF;AAAA;AAAA,EAGA,WAAA,GAA4B;AAC1B,IAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,IAAA,EAAM,CAAA;AAAA,EAC/B;AAAA;AAAA,EAGA,aAAA,GAA8B;AAC5B,IAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,MAAA,EAAQ,CAAA;AAAA,EACjC;AAAA;AAAA,EAGA,cAAA,GAA+C;AAC7C,IAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,OAAA,EAAS,CAAA;AAAA,EAClC;AAAA;AAAA,EAGA,OAAA,GAAwC;AACtC,IAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,OAAA,EAAS,CAAA;AAAA,EAClC;AAAA;AAAA,EAGA,QAAA,GAA+B;AAC7B,IAAA,OAAO,IAAA,CAAK,IAAA;AAAA,EACd;AACF;;;;"}
1
+ {"version":3,"file":"imap-mapped.mjs","sources":["../../src/collections/imap-mapped.mts"],"sourcesContent":["/* eslint-disable unicorn/prefer-iterator-to-array-at-end */\nimport { type WidenLiteral } from 'ts-type-forge';\nimport { Optional, pipe } from '../functional/index.mjs';\nimport { asUint32 } from '../number/index.mjs';\nimport { tp } from '../others/index.mjs';\nimport { type MapSetKeyType, type SizeType } from '../types.mjs';\n\n/**\n * Interface for an immutable map with custom key mapping and lookup operations.\n *\n * IMapMapped allows you to use complex objects as keys by providing\n * transformation functions that convert between your custom key type `K` and a\n * primitive `MapSetKeyType` `KM` that can be efficiently stored in JavaScript's\n * native Map. This enables operations on maps with complex keys while\n * maintaining type safety and immutability.\n *\n * **Key Features:**\n *\n * - **Custom Key Types**: Use any type as keys by providing `toKey`/`fromKey`\n * functions\n * - **Immutable**: All operations return new instances, preserving immutability\n * - **Type Safe**: Full TypeScript support with generic key/value types\n *\n * **Performance Characteristics:**\n *\n * - get/has: O(1) average case (plus key transformation overhead)\n * - set/delete: O(n) due to copying for immutability (plus key transformation\n * overhead)\n * - map/filter operations: O(n)\n * - iteration: O(n) (plus key transformation overhead)\n *\n * @template K The type of the custom keys in the map.\n * @template V The type of the values in the map.\n * @template KM The type of the mapped primitive keys (string, number, etc.).\n */\ntype IMapMappedInterface<K, V, KM extends MapSetKeyType> = Readonly<{\n // Getting information\n\n /**\n * The number of elements in the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * assert.isTrue(map.size === 2);\n * ```\n */\n size: SizeType.Arr;\n\n /**\n * Checks if a key exists in the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [[{ x: 1, y: 2 }, 'A']],\n * toKey,\n * fromKey,\n * );\n *\n * assert.isTrue(map.has({ x: 1, y: 2 }));\n *\n * assert.isFalse(map.has({ x: 3, y: 4 }));\n * ```\n *\n * @param key The key to check.\n * @returns `true` if the key exists, `false` otherwise.\n */\n has: (key: K | (WidenLiteral<K> & {})) => boolean;\n\n /**\n * Retrieves the value associated with a key.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [[{ x: 1, y: 2 }, 'A']],\n * toKey,\n * fromKey,\n * );\n *\n * assert.deepStrictEqual(map.get({ x: 1, y: 2 }), Optional.some('A'));\n *\n * assert.deepStrictEqual(map.get({ x: 0, y: 0 }), Optional.none);\n * ```\n *\n * @param key The key to retrieve.\n * @returns The value associated with the key wrapped with `Optional.some`, or\n * `Optional.none` if the key does not exist.\n */\n get: (key: K | (WidenLiteral<K> & {})) => Optional<V>;\n\n // Reducing a value\n\n /**\n * Checks if all elements in the map satisfy a predicate. Also supports a\n * type predicate overload that narrows the type of values in the map if the\n * predicate returns true for all elements.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, number, string>(\n * [\n * [{ x: 0, y: 0 }, 2],\n * [{ x: 1, y: 0 }, 4],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const allEven = map.every((value) => value % 2 === 0);\n *\n * const isNarrowed = map.every((value): value is 2 | 4 => value % 2 === 0);\n *\n * assert.isTrue(allEven);\n *\n * assert.isTrue(isNarrowed);\n * ```\n *\n * @template W The narrowed type of the values.\n * @param predicate A function to test each key-value pair.\n * @returns `true` if all elements satisfy the predicate, `false` otherwise.\n */\n every: ((predicate: (value: V, key: K) => boolean) => boolean) &\n (<W extends V>(\n predicate: (value: V, key: K) => value is W,\n ) => this is IMapMapped<K, W, KM>);\n\n /**\n * Checks if at least one element in the map satisfies a predicate.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, number, string>(\n * [\n * [{ x: 0, y: 0 }, 3],\n * [{ x: 1, y: 0 }, 7],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * assert.isTrue(map.some((value) => value > 5));\n *\n * assert.isFalse(map.some((value) => value > 10));\n * ```\n *\n * @param predicate A function to test each key-value pair.\n * @returns `true` if at least one element satisfies the predicate, `false`\n * otherwise.\n */\n some: (predicate: (value: V, key: K) => boolean) => boolean;\n\n // Mutation\n\n /**\n * Deletes a key-value pair from the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const original = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const withoutRight = original.delete({ x: 1, y: 0 });\n *\n * assert.deepStrictEqual(\n * original.get({ x: 1, y: 0 }),\n * Optional.some('right'),\n * );\n *\n * assert.deepStrictEqual(withoutRight.get({ x: 1, y: 0 }), Optional.none);\n *\n * assert.isTrue(original.size === 2);\n *\n * assert.isTrue(withoutRight.size === 1);\n * ```\n *\n * @param key The key to delete.\n * @returns A new IMapMapped instance without the specified key.\n */\n delete: (key: K) => IMapMapped<K, V, KM>;\n\n /**\n * Sets a key-value pair in the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const base = IMapMapped.create<Point, string, string>(\n * [[{ x: 0, y: 0 }, 'origin']],\n * toKey,\n * fromKey,\n * );\n *\n * const updated = base.set({ x: 0, y: 0 }, 'home');\n *\n * const extended = base.set({ x: 1, y: 0 }, 'right');\n *\n * assert.deepStrictEqual(base.get({ x: 0, y: 0 }), Optional.some('origin'));\n *\n * assert.deepStrictEqual(updated.get({ x: 0, y: 0 }), Optional.some('home'));\n *\n * assert.deepStrictEqual(\n * extended.get({ x: 1, y: 0 }),\n * Optional.some('right'),\n * );\n * ```\n *\n * @param key The key to set.\n * @param value The value to associate with the key.\n * @returns A new IMapMapped instance with the specified key-value pair.\n */\n set: (key: K, value: V) => IMapMapped<K, V, KM>;\n\n /**\n * Updates the value associated with a key using an updater function.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const scores = IMapMapped.create<Point, number, string>(\n * [\n * [{ x: 0, y: 0 }, 10],\n * [{ x: 1, y: 0 }, 8],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const boosted = scores.update({ x: 0, y: 0 }, (value) => value + 5);\n *\n * const unchanged = scores.update({ x: 9, y: 9 }, (value) => value + 1);\n *\n * assert.deepStrictEqual(boosted.get({ x: 0, y: 0 }), Optional.some(15));\n *\n * assert.deepStrictEqual(scores.get({ x: 0, y: 0 }), Optional.some(10));\n *\n * assert.isTrue(unchanged === scores);\n * ```\n *\n * @param key The key whose value to update.\n * @param updater A function that takes the current value and returns the new\n * value.\n * @returns A new IMapMapped instance with the updated value.\n */\n update: (key: K, updater: (value: V) => V) => IMapMapped<K, V, KM>;\n\n /**\n * Applies a series of mutations to the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const base = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const mutated = base.withMutations([\n * { type: 'set', key: { x: 2, y: 0 }, value: 'far' },\n * { type: 'update', key: { x: 1, y: 0 }, updater: (v) => v.toUpperCase() },\n * { type: 'delete', key: { x: 0, y: 0 } },\n * ]);\n *\n * assert.deepStrictEqual(mutated.get({ x: 2, y: 0 }), Optional.some('far'));\n *\n * assert.deepStrictEqual(mutated.get({ x: 1, y: 0 }), Optional.some('RIGHT'));\n *\n * assert.deepStrictEqual(mutated.get({ x: 0, y: 0 }), Optional.none);\n *\n * assert.deepStrictEqual(base.get({ x: 1, y: 0 }), Optional.some('right'));\n * ```\n *\n * @param actions An array of mutation actions (delete, set, or update).\n * @returns A new IMapMapped instance with all mutations applied.\n */\n withMutations: (\n actions: readonly Readonly<\n | { type: 'delete'; key: K }\n | { type: 'set'; key: K; value: V }\n | { type: 'update'; key: K; updater: (value: V) => V }\n >[],\n ) => IMapMapped<K, V, KM>;\n\n // Sequence algorithms\n\n /**\n * Maps the values of the map to new values.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, number, string>(\n * [\n * [{ x: 0, y: 0 }, 1],\n * [{ x: 1, y: 0 }, 2],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const doubled = map.map((value) => value * 2);\n *\n * assert.deepStrictEqual(Array.from(doubled), [\n * [{ x: 0, y: 0 }, 2],\n * [{ x: 1, y: 0 }, 4],\n * ]);\n * ```\n *\n * @template V2 The type of the new values.\n * @param mapFn A function that maps a value and key to a new value.\n * @returns A new IMapMapped instance with mapped values.\n */\n map: <V2>(mapFn: (value: V, key: K) => V2) => IMapMapped<K, V2, KM>;\n\n /**\n * Maps the keys of the map to new keys. Note: The key type cannot be changed\n * because `toKey` and `fromKey` would become unusable.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const shifted = map.mapKeys((p) => ({ x: p.x + 10, y: p.y + 10 }));\n *\n * assert.deepStrictEqual(Array.from(shifted), [\n * [{ x: 10, y: 10 }, 'origin'],\n * [{ x: 11, y: 10 }, 'right'],\n * ]);\n * ```\n *\n * @param mapFn A function that maps a key to a new key of the same type.\n * @returns A new IMapMapped instance with mapped keys.\n */\n mapKeys: (mapFn: (key: K) => K) => IMapMapped<K, V, KM>;\n\n /**\n * Maps the entries (key-value pairs) of the map to new entries.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, number, string>(\n * [\n * [{ x: 0, y: 0 }, 1],\n * [{ x: 1, y: 0 }, 2],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const labeled = map.mapEntries(([key, value]) => [key, `value=${value}`]);\n *\n * assert.deepStrictEqual(Array.from(labeled), [\n * [{ x: 0, y: 0 }, 'value=1'],\n * [{ x: 1, y: 0 }, 'value=2'],\n * ]);\n * ```\n *\n * @template V2 The type of the new values in the entries.\n * @param mapFn A function that maps an entry to a new entry (key must remain\n * the same type).\n * @returns A new IMapMapped instance with mapped entries.\n */\n mapEntries: <V2>(\n mapFn: (entry: readonly [K, V]) => readonly [K, V2],\n ) => IMapMapped<K, V2, KM>;\n\n // Side effects\n\n /**\n * Executes a callback function for each key-value pair in the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const mut_entries: (readonly [Point, string])[] = [];\n *\n * map.forEach((value, key) => {\n * mut_entries.push([key, value]);\n * });\n *\n * assert.deepStrictEqual(mut_entries, [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ]);\n * ```\n *\n * @param callbackfn A function to execute for each element.\n */\n forEach: (callbackfn: (value: V, key: K) => void) => void;\n\n // Iterators\n\n /**\n * Returns an iterator for the keys in the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const keys = Array.from(map.keys());\n *\n * assert.deepStrictEqual(keys, [\n * { x: 0, y: 0 },\n * { x: 1, y: 0 },\n * ]);\n * ```\n *\n * @returns An iterable iterator of keys.\n */\n keys: () => IterableIterator<K>;\n\n /**\n * Returns an iterator for the values in the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const values = Array.from(map.values());\n *\n * assert.deepStrictEqual(values, ['origin', 'right']);\n * ```\n *\n * @returns An iterable iterator of values.\n */\n values: () => IterableIterator<V>;\n\n /**\n * Returns an iterator for the entries (key-value pairs) in the map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const entries = Array.from(map.entries());\n *\n * assert.deepStrictEqual(entries, [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ]);\n * ```\n *\n * @returns An iterable iterator of entries.\n */\n entries: () => IterableIterator<readonly [K, V]>;\n\n // Conversion\n\n /**\n * Converts the keys of the map to an array.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * assert.deepStrictEqual(map.toKeysArray(), [\n * { x: 0, y: 0 },\n * { x: 1, y: 0 },\n * ]);\n * ```\n *\n * @returns A readonly array of keys.\n */\n toKeysArray: () => readonly K[];\n\n /**\n * Converts the values of the map to an array.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * assert.deepStrictEqual(map.toValuesArray(), ['origin', 'right']);\n * ```\n *\n * @returns A readonly array of values.\n */\n toValuesArray: () => readonly V[];\n\n /**\n * Converts the entries (key-value pairs) of the map to an array.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * assert.deepStrictEqual(map.toEntriesArray(), [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ]);\n * ```\n *\n * @returns A readonly array of entries.\n */\n toEntriesArray: () => readonly (readonly [K, V])[];\n\n /**\n * Converts the map to an array of entries (key-value pairs). Alias for\n * `toEntriesArray`.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * assert.deepStrictEqual(map.toArray(), [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ]);\n * ```\n *\n * @returns A readonly array of entries.\n */\n toArray: () => readonly (readonly [K, V])[];\n\n /**\n * Returns the underlying readonly JavaScript Map.\n *\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [[{ x: 1, y: 2 }, 'A']],\n * toKey,\n * fromKey,\n * );\n *\n * const raw = map.toRawMap();\n *\n * assert.isTrue(isMap(raw));\n *\n * assert.isTrue(raw.get(toKey({ x: 1, y: 2 })) === 'A');\n * ```\n *\n * @returns The raw ReadonlyMap instance.\n */\n toRawMap: () => ReadonlyMap<KM, V>;\n}>;\n\n/**\n * Represents an immutable map with custom key transformation and\n * high-performance operations.\n *\n * IMapMapped is a specialized persistent data structure that enables using\n * complex objects as map keys while maintaining the performance benefits of\n * JavaScript's native Map. It achieves this by requiring bidirectional\n * transformation functions that convert between your custom key type and a\n * primitive type that can be efficiently stored and compared.\n *\n * **Key Features:**\n *\n * - **Complex Keys**: Use objects, arrays, or any custom type as map keys\n * - **Immutable**: All mutation operations return new instances\n * - **Type Safe**: Full TypeScript support with compile-time key/value type\n * checking\n * - **Bidirectional**: Maintains ability to reconstruct original keys from mapped\n * keys\n *\n * **Use Cases:**\n *\n * - Maps with composite keys (e.g., coordinates, user IDs with metadata)\n * - Caching with complex cache keys\n * - State management where entities have multi-part identifiers\n * - Performance-critical maps with non-primitive keys\n *\n * @template K The type of the custom keys in the map.\n * @template V The type of the values in the map.\n * @template KM The type of the mapped primitive keys (string, number, etc.).\n */\nexport type IMapMapped<K, V, KM extends MapSetKeyType> = Iterable<\n readonly [K, V]\n> &\n IMapMappedInterface<K, V, KM>;\n\n/** Provides utility functions for IMapMapped. */\nexport namespace IMapMapped {\n /**\n * Creates a new IMapMapped instance with custom key transformation functions.\n *\n * This factory function creates an immutable map that can use complex objects\n * as keys by providing bidirectional transformation functions. The `toKey`\n * function converts your custom key type to a primitive type that can be\n * efficiently stored, while `fromKey` reconstructs the original key type for\n * iteration and access.\n *\n * **Performance:** O(n) where n is the number of entries in the iterable.\n *\n * @template K The type of the custom keys.\n * @template V The type of the values.\n * @template KM The type of the mapped primitive keys.\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * assert.isTrue(map.size === 2);\n *\n * assert.deepStrictEqual(map.get({ x: 0, y: 0 }), Optional.some('origin'));\n * ```\n *\n * @param iterable An iterable of key-value pairs using the custom key type.\n * @param toKey A function that converts a custom key `K` to a primitive key\n * `KM`. This function must be deterministic and produce unique values for\n * unique keys.\n * @param fromKey A function that converts a primitive key `KM` back to the\n * custom key `K`. This should be the inverse of `toKey`.\n * @returns A new IMapMapped instance containing all entries from the\n * iterable.\n */\n export const create = <K, V, KM extends MapSetKeyType>(\n iterable: Iterable<readonly [K, V]>,\n toKey: (a: K) => KM,\n fromKey: (k: KM) => K,\n ): IMapMapped<K, V, KM> =>\n new IMapMappedClass<K, V, KM>(iterable, toKey, fromKey);\n\n /**\n * Checks if two IMapMapped instances are structurally equal.\n *\n * Two IMapMapped instances are considered equal if they have the same size\n * and contain exactly the same key-value pairs. The comparison is performed\n * on the underlying mapped keys and values, so the transformation functions\n * themselves don't need to be identical. Values are compared using\n * JavaScript's `===` operator.\n *\n * **Performance:** O(n) where n is the size of the smaller map.\n *\n * @template K The type of the custom keys.\n * @template V The type of the values.\n * @template KM The type of the mapped primitive keys.\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const first = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const second = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 1, y: 0 }, 'right'],\n * [{ x: 0, y: 0 }, 'origin'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const third = IMapMapped.create<Point, string, string>(\n * [[{ x: 0, y: 0 }, 'different']],\n * toKey,\n * fromKey,\n * );\n *\n * assert.isTrue(IMapMapped.equal(first, second));\n *\n * assert.isFalse(IMapMapped.equal(first, third));\n * ```\n *\n * @param a The first IMapMapped instance to compare.\n * @param b The second IMapMapped instance to compare.\n * @returns `true` if the maps contain exactly the same key-value pairs,\n * `false` otherwise.\n */\n export const equal = <K, V, KM extends MapSetKeyType>(\n a: IMapMapped<K, V, KM>,\n b: IMapMapped<K, V, KM>,\n ): boolean =>\n a.size === b.size &&\n a.every(\n (v, k) =>\n pipe(b.get(k)).map((bv) => Optional.isSome(bv) && bv.value === v).value,\n );\n}\n\n/**\n * Internal class implementation for IMapMapped providing immutable map\n * operations with key transformation.\n *\n * This class implements the IMapMapped interface by maintaining a JavaScript\n * Map with primitive keys internally while exposing an API that works with\n * custom key types. The transformation between custom and primitive keys is\n * handled transparently through the provided `toKey` and `fromKey` functions.\n *\n * **Implementation Details:**\n *\n * - Uses ReadonlyMap<KM, V> internally where KM is the primitive key type\n * - Stores transformation functions for bidirectional key conversion\n * - Implements copy-on-write semantics for efficiency\n * - Provides optional debug messaging for development\n *\n * @template K The type of the custom keys.\n * @template V The type of the values.\n * @template KM The type of the mapped primitive keys.\n * @implements IMapMapped\n * @implements Iterable\n * @internal This class should not be used directly. Use IMapMapped.create() instead.\n */\nclass IMapMappedClass<K, V, KM extends MapSetKeyType>\n implements IMapMapped<K, V, KM>, Iterable<readonly [K, V]>\n{\n readonly #map: ReadonlyMap<KM, V>;\n readonly #toKey: (a: K) => KM;\n readonly #fromKey: (k: KM) => K;\n readonly #showNotFoundMessage: boolean;\n\n /**\n * Constructs an IMapMappedClass instance with custom key transformation.\n *\n * @param iterable An iterable of key-value pairs using the custom key type K.\n * @param toKey A function that converts a custom key K to a primitive key KM.\n * Must be deterministic and produce unique values for unique keys.\n * @param fromKey A function that converts a primitive key KM back to the\n * custom key K. Should be the inverse of the toKey function.\n * @param showNotFoundMessage Whether to log warning messages when operations\n * are performed on non-existent keys. Useful for debugging. Defaults to\n * false for production use.\n * @internal Use IMapMapped.create() instead of calling this constructor directly.\n */\n constructor(\n iterable: Iterable<readonly [K, V]>,\n toKey: (a: K) => KM,\n fromKey: (k: KM) => K,\n showNotFoundMessage: boolean = false,\n ) {\n this.#map = new Map(Array.from(iterable, ([k, v]) => [toKey(k), v]));\n\n this.#toKey = toKey;\n\n this.#fromKey = fromKey;\n\n this.#showNotFoundMessage = showNotFoundMessage;\n }\n\n /** @inheritdoc */\n get size(): SizeType.Arr {\n return asUint32(this.#map.size);\n }\n\n /** @inheritdoc */\n has(key: K | (WidenLiteral<K> & {})): boolean {\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return this.#map.has(this.#toKey(key as K));\n }\n\n /** @inheritdoc */\n get(key: K | (WidenLiteral<K> & {})): Optional<V> {\n if (!this.has(key)) return Optional.none;\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, total-functions/no-unsafe-type-assertion\n return Optional.some(this.#map.get(this.#toKey(key as K))!);\n }\n\n /** @inheritdoc */\n every<W extends V>(\n predicate: (value: V, key: K) => value is W,\n ): this is IMapMapped<K, W, KM>;\n\n /** @inheritdoc */\n every(predicate: (value: V, key: K) => boolean): boolean;\n\n /** @inheritdoc */\n every(predicate: (value: V, key: K) => boolean): boolean {\n for (const [k, v] of this.entries()) {\n if (!predicate(v, k)) return false;\n }\n\n return true;\n }\n\n /** @inheritdoc */\n some(predicate: (value: V, key: K) => boolean): boolean {\n for (const [k, v] of this.entries()) {\n if (predicate(v, k)) return true;\n }\n\n return false;\n }\n\n /** @inheritdoc */\n delete(key: K): IMapMapped<K, V, KM> {\n if (!this.has(key)) {\n if (this.#showNotFoundMessage) {\n console.warn(\n `IMapMapped.delete: key not found: ${String(this.#toKey(key))}`,\n );\n }\n\n return this;\n }\n\n const keyMapped = this.#toKey(key);\n\n return IMapMapped.create(\n Array.from(this.#map)\n .filter(([km]) => !Object.is(km, keyMapped))\n .map(([km, v]) => tp(this.#fromKey(km), v)),\n this.#toKey,\n this.#fromKey,\n );\n }\n\n /** @inheritdoc */\n set(key: K, value: V): IMapMapped<K, V, KM> {\n const curr = this.get(key);\n\n if (Optional.isSome(curr) && value === curr.value) return this;\n\n const keyMapped = this.#toKey(key);\n\n if (!this.has(key)) {\n return IMapMapped.create(\n [...this.#map, tp(keyMapped, value)].map(([km, v]) =>\n tp(this.#fromKey(km), v),\n ),\n this.#toKey,\n this.#fromKey,\n );\n }\n\n return IMapMapped.create(\n Array.from(this.#map, ([km, v]) =>\n tp(this.#fromKey(km), Object.is(km, keyMapped) ? value : v),\n ),\n this.#toKey,\n this.#fromKey,\n );\n }\n\n /** @inheritdoc */\n update(key: K, updater: (value: V) => V): IMapMapped<K, V, KM> {\n const curr = this.get(key);\n\n if (Optional.isNone(curr)) {\n if (this.#showNotFoundMessage) {\n console.warn(\n `IMapMapped.update: key not found: ${String(this.#toKey(key))}`,\n );\n }\n\n return this;\n }\n\n const keyMapped = this.#toKey(key);\n\n return IMapMapped.create(\n Array.from(this.#map, ([km, v]) =>\n tp(\n this.#fromKey(km),\n Object.is(km, keyMapped) ? updater(curr.value) : v,\n ),\n ),\n this.#toKey,\n this.#fromKey,\n );\n }\n\n /** @inheritdoc */\n withMutations(\n actions: readonly Readonly<\n | { type: 'delete'; key: K }\n | { type: 'set'; key: K; value: V }\n | { type: 'update'; key: K; updater: (value: V) => V }\n >[],\n ): IMapMapped<K, V, KM> {\n const mut_result = new Map<KM, V>(this.#map);\n\n const updateFn = (\n action: Readonly<\n | { type: 'delete'; key: K }\n | { type: 'set'; key: K; value: V }\n | { type: 'update'; key: K; updater: (value: V) => V }\n >,\n ): void => {\n const key = this.#toKey(action.key);\n\n switch (action.type) {\n case 'delete':\n mut_result.delete(key);\n\n break;\n\n case 'set':\n mut_result.set(key, action.value);\n\n break;\n\n case 'update': {\n const curr = mut_result.get(key);\n\n if (curr === undefined || !mut_result.has(key)) {\n if (this.#showNotFoundMessage) {\n console.warn(\n `IMapMapped.withMutations::update: key not found: ${String(key)}`,\n );\n }\n\n break;\n }\n\n mut_result.set(key, action.updater(curr));\n\n break;\n }\n }\n };\n\n for (const action of actions) {\n updateFn(action);\n }\n\n return IMapMapped.create<K, V, KM>(\n Array.from(mut_result, ([k, v]) => [this.#fromKey(k), v]),\n this.#toKey,\n this.#fromKey,\n );\n }\n\n /** @inheritdoc */\n map<V2>(mapFn: (value: V, key: K) => V2): IMapMapped<K, V2, KM> {\n return IMapMapped.create(\n this.toArray().map(([k, v]) => tp(k, mapFn(v, k))),\n this.#toKey,\n this.#fromKey,\n );\n }\n\n /** @inheritdoc */\n mapKeys(mapFn: (key: K) => K): IMapMapped<K, V, KM> {\n return IMapMapped.create(\n this.toArray().map(([k, v]) => tp(mapFn(k), v)),\n this.#toKey,\n this.#fromKey,\n );\n }\n\n /** @inheritdoc */\n mapEntries<V2>(\n mapFn: (entry: readonly [K, V]) => readonly [K, V2],\n ): IMapMapped<K, V2, KM> {\n return IMapMapped.create(\n this.toArray().map(mapFn),\n this.#toKey,\n this.#fromKey,\n );\n }\n\n /** @inheritdoc */\n forEach(callbackfn: (value: V, key: K) => void): void {\n for (const [km, value] of this.#map) {\n callbackfn(value, this.#fromKey(km));\n }\n }\n\n /**\n * @example\n *\n * ```ts\n * type Point = Readonly<{ x: number; y: number }>;\n *\n * const toKey = (p: Point) => JSON.stringify(p);\n *\n * // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n * const fromKey = (key: string) => JSON.parse(key) as Point;\n *\n * const map = IMapMapped.create<Point, string, string>(\n * [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ],\n * toKey,\n * fromKey,\n * );\n *\n * const collected = Array.from(map);\n *\n * assert.deepStrictEqual(collected, [\n * [{ x: 0, y: 0 }, 'origin'],\n * [{ x: 1, y: 0 }, 'right'],\n * ]);\n * ```\n *\n * @inheritdoc\n */\n *[Symbol.iterator](): Iterator<readonly [K, V]> {\n for (const e of this.entries()) {\n yield e;\n }\n }\n\n /** @inheritdoc */\n *keys(): IterableIterator<K> {\n for (const km of this.#map.keys()) {\n yield this.#fromKey(km);\n }\n }\n\n /** @inheritdoc */\n values(): IterableIterator<V> {\n return this.#map.values();\n }\n\n /** @inheritdoc */\n *entries(): IterableIterator<readonly [K, V]> {\n for (const [km, v] of this.#map) {\n yield [this.#fromKey(km), v];\n }\n }\n\n /** @inheritdoc */\n toKeysArray(): readonly K[] {\n return Array.from(this.keys());\n }\n\n /** @inheritdoc */\n toValuesArray(): readonly V[] {\n return Array.from(this.values());\n }\n\n /** @inheritdoc */\n toEntriesArray(): readonly (readonly [K, V])[] {\n return Array.from(this.entries());\n }\n\n /** @inheritdoc */\n toArray(): readonly (readonly [K, V])[] {\n return Array.from(this.entries());\n }\n\n /** @inheritdoc */\n toRawMap(): ReadonlyMap<KM, V> {\n return this.#map;\n }\n}\n"],"names":["IMapMapped","Optional.isSome","Optional.none","Optional.some","Optional.isNone"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAozBO,IAAU;AAAA,CAAV,CAAUA,WAAAA,KAAV;AAgDE,EAAMA,WAAAA,CAAA,MAAA,GAAS,CACpB,QAAA,EACA,KAAA,EACA,YAEA,IAAI,eAAA,CAA0B,QAAA,EAAU,KAAA,EAAO,OAAO,CAAA;AA4DjD,EAAMA,WAAAA,CAAA,QAAQ,CACnB,CAAA,EACA,MAEA,CAAA,CAAE,IAAA,KAAS,CAAA,CAAE,IAAA,IACb,CAAA,CAAE,KAAA;AAAA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,KAAK,MAAA,EAAO;AAAA,EAC1B;AAAA;AAAA,EAGA,CAAC,OAAA,GAA6C;AAC5C,IAAA,KAAA,MAAW,CAAC,EAAA,EAAI,CAAC,CAAA,IAAK,KAAK,IAAA,EAAM;AAC/B,MAAA,MAAM,CAAC,IAAA,CAAK,QAAA,CAAS,EAAE,GAAG,CAAC,CAAA;AAAA,IAC7B;AAAA,EACF;AAAA;AAAA,EAGA,WAAA,GAA4B;AAC1B,IAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,IAAA,EAAM,CAAA;AAAA,EAC/B;AAAA;AAAA,EAGA,aAAA,GAA8B;AAC5B,IAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,MAAA,EAAQ,CAAA;AAAA,EACjC;AAAA;AAAA,EAGA,cAAA,GAA+C;AAC7C,IAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,OAAA,EAAS,CAAA;AAAA,EAClC;AAAA;AAAA,EAGA,OAAA,GAAwC;AACtC,IAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,OAAA,EAAS,CAAA;AAAA,EAClC;AAAA;AAAA,EAGA,QAAA,GAA+B;AAC7B,IAAA,OAAO,IAAA,CAAK,IAAA;AAAA,EACd;AACF;;;;"}
@@ -148,7 +148,7 @@ class IMapClass {
148
148
  case "update": {
149
149
  const { key } = action;
150
150
  const curr = mut_result.get(key);
151
- if (!mut_result.has(key) || curr === void 0) {
151
+ if (curr === void 0 || !mut_result.has(key)) {
152
152
  if (this.#showNotFoundMessage) {
153
153
  const keyStr = unknownToString(key);
154
154
  console.warn(`IMap.withMutations: key not found: ${keyStr}`);
@@ -1 +1 @@
1
- {"version":3,"file":"imap.mjs","sources":["../../src/collections/imap.mts"],"sourcesContent":["/* eslint-disable unicorn/prefer-iterator-to-array-at-end */\nimport { type WidenLiteral } from 'ts-type-forge';\nimport { Optional, pipe } from '../functional/index.mjs';\nimport { asUint32 } from '../number/index.mjs';\nimport { tp, unknownToString } from '../others/index.mjs';\nimport { type MapSetKeyType, type SizeType } from '../types.mjs';\n\n/**\n * Interface for an immutable map with lookup operations and functional\n * programming patterns.\n *\n * This interface defines all methods and properties available on IMap\n * instances. All operations that modify the map return new IMap instances,\n * preserving immutability. The underlying implementation uses JavaScript's\n * native Map but creates copies on mutations to maintain immutability.\n *\n * **Immutability Guarantees:**\n *\n * - All mutation operations (set, delete, update) return new IMap instances\n * - Original IMap instances are never modified\n * - Safe for concurrent access and functional programming patterns\n *\n * **Performance Characteristics:**\n *\n * - get/has: O(1) average case\n * - set/delete: O(n) due to copying for immutability\n * - map/filter operations: O(n)\n * - iteration: O(n)\n *\n * @template K The type of the keys in the map. Must extend MapSetKeyType\n * (string, number, boolean, etc.)\n * @template V The type of the values in the map.\n */\ntype IMapInterface<K extends MapSetKeyType, V> = Readonly<{\n // Getting information\n\n /**\n * The number of elements in the map.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['a', 1],\n * ['b', 2],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * assert.isTrue(map.size === 2);\n * ```\n */\n size: SizeType.Arr;\n\n /**\n * Checks if a key exists in the map. Allows for wider literal types for keys\n * during checking.\n *\n * @example\n *\n * ```ts\n * const map = IMap.create<'id' | 'enabled', number | boolean>([\n * ['id', 42],\n * ['enabled', true],\n * ]);\n *\n * assert.isTrue(map.has('id'));\n *\n * assert.isFalse(map.has('missing'));\n * ```\n *\n * @param key The key to check.\n * @returns `true` if the key exists, `false` otherwise.\n */\n has: (key: K | (WidenLiteral<K> & {})) => boolean;\n\n /**\n * Retrieves the value associated with a key.\n *\n * @example\n *\n * ```ts\n * const map = IMap.create([['user', { id: 1 }]]);\n *\n * assert.deepStrictEqual(map.get('user'), Optional.some({ id: 1 }));\n *\n * assert.deepStrictEqual(map.get('missing'), Optional.none);\n * ```\n *\n * @param key The key to retrieve.\n * @returns The value associated with the key wrapped with `Optional.some`, or\n * `Optional.none` if the key does not exist.\n */\n get: (key: K | (WidenLiteral<K> & {})) => Optional<V>;\n\n // Reducing a value\n\n /**\n * Checks if all elements in the map satisfy a predicate. Also supports a\n * type predicate overload that narrows the type of values in the map if the\n * predicate returns true for all elements.\n *\n * @example\n *\n * ```ts\n * const map = IMap.create([\n * ['a', 2],\n * ['b', 4],\n * ]);\n *\n * const allEven = map.every((value) => value % 2 === 0);\n *\n * const isNarrowed = map.every((value): value is 2 | 4 => value % 2 === 0);\n *\n * assert.isTrue(allEven);\n *\n * assert.isTrue(isNarrowed);\n * ```\n *\n * @template W The narrowed type of the values.\n * @param predicate A function to test each key-value pair.\n * @returns `true` if all elements satisfy the predicate, `false` otherwise.\n */\n every: ((predicate: (value: V, key: K) => boolean) => boolean) &\n (<W extends V>(\n predicate: (value: V, key: K) => value is W,\n ) => this is IMap<K, W>);\n\n /**\n * Checks if at least one element in the map satisfies a predicate.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['alice', 3],\n * ['bob', 5],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * assert.isTrue(map.some((value) => value > 4));\n *\n * assert.isFalse(map.some((value) => value > 10));\n * ```\n *\n * @param predicate A function to test each key-value pair.\n * @returns `true` if at least one element satisfies the predicate, `false`\n * otherwise.\n */\n some: (predicate: (value: V, key: K) => boolean) => boolean;\n\n // Mutation\n\n /**\n * Deletes a key-value pair from the map.\n *\n * @example\n *\n * ```ts\n * const original = IMap.create([\n * ['a', 1],\n * ['b', 2],\n * ]);\n *\n * const withoutB = original.delete('b');\n *\n * assert.deepStrictEqual(original.get('b'), Optional.some(2));\n *\n * assert.deepStrictEqual(withoutB.get('b'), Optional.none);\n *\n * assert.isTrue(original.size === 2);\n *\n * assert.isTrue(withoutB.size === 1);\n * ```\n *\n * @param key The key to delete.\n * @returns A new IMap instance without the specified key.\n */\n delete: (key: K) => IMap<K, V>;\n\n /**\n * Sets a key-value pair in the map.\n *\n * @example\n *\n * ```ts\n * const entries = [['count', 1]] as const satisfies readonly (readonly [\n * 'count' | 'status',\n * number | string,\n * ])[];\n *\n * const base = IMap.create<'count' | 'status', number | string>(entries);\n *\n * const updated = base.set('count', 2);\n *\n * const extended = base.set('status', 'ok');\n *\n * assert.deepStrictEqual(base.get('count'), Optional.some(1));\n *\n * assert.deepStrictEqual(updated.get('count'), Optional.some(2));\n *\n * assert.deepStrictEqual(extended.get('status'), Optional.some('ok'));\n * ```\n *\n * @param key The key to set.\n * @param value The value to associate with the key.\n * @returns A new IMap instance with the specified key-value pair.\n */\n set: (key: K, value: V) => IMap<K, V>;\n\n /**\n * Updates the value associated with a key using an updater function.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['alice', 10],\n * ['bob', 8],\n * ] as const satisfies readonly (readonly [\n * 'alice' | 'bob' | 'charlie',\n * number,\n * ])[];\n *\n * const scores = IMap.create<'alice' | 'bob' | 'charlie', number>(entries);\n *\n * const boosted = scores.update('alice', (value) => value + 5);\n *\n * const unchanged = scores.update('charlie', (value) => value + 1);\n *\n * assert.deepStrictEqual(boosted.get('alice'), Optional.some(15));\n *\n * assert.deepStrictEqual(scores.get('alice'), Optional.some(10));\n *\n * assert.isTrue(unchanged === scores);\n * ```\n *\n * @param key The key whose value to update.\n * @param updater A function that takes the current value and returns the new\n * value.\n * @returns A new IMap instance with the updated value.\n */\n update: (key: K, updater: (value: V) => V) => IMap<K, V>;\n\n /**\n * Applies a series of mutations to the map.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['a', 1],\n * ['b', 2],\n * ] as const satisfies readonly (readonly ['a' | 'b' | 'c', number])[];\n *\n * const base = IMap.create<'a' | 'b' | 'c', number>(entries);\n *\n * const actions: readonly Readonly<\n * | { type: 'set'; key: 'c'; value: number }\n * | { type: 'update'; key: 'b'; updater: (value: number) => number }\n * | { type: 'delete'; key: 'a' }\n * >[] = [\n * { type: 'set', key: 'c', value: 3 },\n * { type: 'update', key: 'b', updater: (value) => value * 10 },\n * { type: 'delete', key: 'a' },\n * ] as const;\n *\n * const mutated = base.withMutations(actions);\n *\n * assert.deepStrictEqual(mutated.get('c'), Optional.some(3));\n *\n * assert.deepStrictEqual(mutated.get('b'), Optional.some(20));\n *\n * assert.deepStrictEqual(mutated.get('a'), Optional.none);\n *\n * assert.deepStrictEqual(base.get('b'), Optional.some(2));\n * ```\n *\n * @param actions An array of mutation actions (delete, set, or update).\n * @returns A new IMap instance with all mutations applied.\n */\n withMutations: (\n actions: readonly Readonly<\n | { type: 'delete'; key: K }\n | { type: 'set'; key: K; value: V }\n | { type: 'update'; key: K; updater: (value: V) => V }\n >[],\n ) => IMap<K, V>;\n\n // Sequence algorithms\n\n /**\n * Maps the values of the map to new values.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['a', 1],\n * ['b', 2],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * const doubled = map.map((value) => value * 2);\n *\n * assert.deepStrictEqual(Array.from(doubled), [\n * ['a', 2],\n * ['b', 4],\n * ]);\n * ```\n *\n * @template V2 The type of the new values.\n * @param mapFn A function that maps a value and key to a new value.\n * @returns A new IMap instance with mapped values.\n */\n map: <V2>(mapFn: (value: V, key: K) => V2) => IMap<K, V2>;\n\n /**\n * Maps the keys of the map to new keys.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['first', 1],\n * ['second', 2],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * const upperKeys = map.mapKeys((key) => key.toUpperCase());\n *\n * assert.deepStrictEqual(Array.from(upperKeys), [\n * ['FIRST', 1],\n * ['SECOND', 2],\n * ]);\n * ```\n *\n * @template K2 The type of the new keys.\n * @param mapFn A function that maps a key to a new key.\n * @returns A new IMap instance with mapped keys and original values.\n */\n mapKeys: <K2 extends MapSetKeyType>(mapFn: (key: K) => K2) => IMap<K2, V>;\n\n /**\n * Maps the entries (key-value pairs) of the map to new entries.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['a', 1],\n * ['b', 2],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * const swapped = map.mapEntries(\n * ([key, value]) => [value, key] satisfies readonly [number, string],\n * );\n *\n * assert.deepStrictEqual(Array.from(swapped), [\n * [1, 'a'],\n * [2, 'b'],\n * ]);\n * ```\n *\n * @template K2 The type of the new keys in the entries.\n * @template V2 The type of the new values in the entries.\n * @param mapFn A function that maps an entry to a new entry.\n * @returns A new IMap instance with mapped entries.\n */\n mapEntries: <K2 extends MapSetKeyType, V2>(\n mapFn: (entry: readonly [K, V]) => readonly [K2, V2],\n ) => IMap<K2, V2>;\n\n // Side effects\n\n /**\n * Executes a callback function for each key-value pair in the map.\n *\n * @example\n *\n * ```ts\n * const map = IMap.create([\n * ['a', 1],\n * ['b', 2],\n * ]);\n *\n * const mut_entries: (readonly [string, number])[] = [];\n *\n * map.forEach((value, key) => {\n * mut_entries.push([key, value]);\n * });\n *\n * assert.deepStrictEqual(mut_entries, [\n * ['a', 1],\n * ['b', 2],\n * ]);\n * ```\n *\n * @param callbackfn A function to execute for each element.\n */\n forEach: (callbackfn: (value: V, key: K) => void) => void;\n\n // Iterators\n\n /**\n * Returns an iterator for the keys in the map.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['a', 1],\n * ['b', 2],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * const keys = Array.from(map.keys());\n *\n * assert.deepStrictEqual(keys, ['a', 'b']);\n * ```\n *\n * @returns An iterable iterator of keys.\n */\n keys: () => IterableIterator<K>;\n\n /**\n * Returns an iterator for the values in the map.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['a', 1],\n * ['b', 2],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * const values = Array.from(map.values());\n *\n * assert.deepStrictEqual(values, [1, 2]);\n * ```\n *\n * @returns An iterable iterator of values.\n */\n values: () => IterableIterator<V>;\n\n /**\n * Returns an iterator for the entries (key-value pairs) in the map.\n *\n * @example\n *\n * ```ts\n * const map = IMap.create([\n * ['a', 1],\n * ['b', 2],\n * ]);\n *\n * const entries = Array.from(map.entries());\n *\n * assert.deepStrictEqual(entries, [\n * ['a', 1],\n * ['b', 2],\n * ]);\n * ```\n *\n * @returns An iterable iterator of entries.\n */\n entries: () => IterableIterator<readonly [K, V]>;\n\n // Conversion\n\n /**\n * Converts the keys of the map to an array.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['x', 10],\n * ['y', 20],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * assert.deepStrictEqual(map.toKeysArray(), ['x', 'y']);\n * ```\n *\n * @returns A readonly array of keys.\n */\n toKeysArray: () => readonly K[];\n\n /**\n * Converts the values of the map to an array.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['x', 10],\n * ['y', 20],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * assert.deepStrictEqual(map.toValuesArray(), [10, 20]);\n * ```\n *\n * @returns A readonly array of values.\n */\n toValuesArray: () => readonly V[];\n\n /**\n * Converts the entries (key-value pairs) of the map to an array.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['a', 1],\n * ['b', 2],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * assert.deepStrictEqual(map.toEntriesArray(), [\n * ['a', 1],\n * ['b', 2],\n * ]);\n * ```\n *\n * @returns A readonly array of entries.\n */\n toEntriesArray: () => readonly (readonly [K, V])[];\n\n /**\n * Converts the map to an array of entries (key-value pairs). Alias for\n * `toEntriesArray`.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['k1', 'v1'],\n * ['k2', 'v2'],\n * ] as const satisfies readonly FixedLengthTuple<2, string>[];\n *\n * const map = IMap.create(entries);\n *\n * assert.deepStrictEqual(map.toArray(), [\n * ['k1', 'v1'],\n * ['k2', 'v2'],\n * ]);\n * ```\n *\n * @returns A readonly array of entries.\n */\n toArray: () => readonly (readonly [K, V])[];\n\n /**\n * Returns the underlying readonly JavaScript Map.\n *\n * @example\n *\n * ```ts\n * const entries = [['key', 1]] as const satisfies readonly (readonly [\n * string,\n * number,\n * ])[];\n *\n * const map = IMap.create(entries);\n *\n * const raw = map.toRawMap();\n *\n * assert.isTrue(isMap(raw));\n *\n * assert.isTrue(raw.get('key') === 1);\n * ```\n *\n * @returns The raw ReadonlyMap instance.\n */\n toRawMap: () => ReadonlyMap<K, V>;\n}>;\n\n/**\n * Represents an immutable map with high-performance operations and functional\n * programming support.\n *\n * IMap is a persistent data structure that provides all the functionality of\n * JavaScript's Map while maintaining immutability. All operations that would\n * normally mutate the map instead return new IMap instances, making it safe for\n * functional programming and concurrent access.\n *\n * **Key Features:**\n *\n * - **Immutable**: All mutation operations return new instances\n * - **Type Safe**: Full TypeScript support with generic key/value types\n * - **Iterable**: Implements standard JavaScript iteration protocols\n * - **Functional**: Rich API for map, filter, reduce-style operations\n *\n * **When to Use:**\n *\n * - State management in functional applications\n * - Caching with immutable guarantees\n * - Data structures that need to be shared across components\n * - When you need Map functionality but want immutability\n *\n * @template K The type of the keys in the map. Must extend MapSetKeyType.\n * @template V The type of the values in the map.\n */\nexport type IMap<K extends MapSetKeyType, V> = Iterable<readonly [K, V]> &\n IMapInterface<K, V>;\n\n/** Provides utility functions for IMap. */\nexport namespace IMap {\n /**\n * Creates a new IMap instance from an iterable of key-value pairs.\n *\n * This factory function accepts any iterable of [key, value] tuples,\n * including arrays, JavaScript Maps, other IMaps, or custom iterables. The\n * resulting IMap will contain all the entries from the input iterable.\n *\n * **Performance:** O(n) where n is the number of entries in the iterable.\n *\n * @example\n *\n * ```ts\n * const map = IMap.create<string, number | string>([\n * ['id', 1],\n * ['status', 'active'],\n * ]);\n *\n * assert.isTrue(map.size === 2);\n *\n * assert.deepStrictEqual(map.get('status'), Optional.some('active'));\n * ```\n *\n * @template K The type of the keys. Must extend MapSetKeyType.\n * @template V The type of the values.\n * @param iterable An iterable of key-value pairs (e.g., Array, Map, IMap,\n * etc.)\n * @returns A new IMap instance containing all entries from the iterable.\n */\n export const create = <K extends MapSetKeyType, V>(\n iterable: Iterable<readonly [K, V]>,\n ): IMap<K, V> => new IMapClass<K, V>(iterable);\n\n /**\n * Checks if two IMap instances are structurally equal.\n *\n * Two IMaps are considered equal if they have the same size and contain\n * exactly the same key-value pairs. The order of entries does not matter for\n * equality comparison. Values are compared using JavaScript's `===`\n * operator.\n *\n * **Performance:** O(n) where n is the size of the smaller map.\n *\n * @example\n *\n * ```ts\n * const first = IMap.create<'a' | 'b', number>([\n * ['a', 1],\n * ['b', 2],\n * ]);\n *\n * const second = IMap.create<'a' | 'b', number>([\n * ['b', 2],\n * ['a', 1],\n * ]);\n *\n * const third = IMap.create<'a' | 'b', number>([\n * ['a', 1],\n * ['b', 3],\n * ]);\n *\n * assert.isTrue(IMap.equal(first, second));\n *\n * assert.isFalse(IMap.equal(first, third));\n * ```\n *\n * @template K The type of the keys.\n * @template V The type of the values.\n * @param a The first IMap instance to compare.\n * @param b The second IMap instance to compare.\n * @returns `true` if the maps contain exactly the same key-value pairs,\n * `false` otherwise.\n */\n export const equal = <K extends MapSetKeyType, V>(\n a: IMap<K, V>,\n b: IMap<K, V>,\n ): boolean =>\n a.size === b.size &&\n a.every(\n (v, k) =>\n pipe(b.get(k)).map((v2) => Optional.isSome(v2) && v2.value === v).value,\n );\n}\n\n/**\n * Internal class implementation for IMap providing immutable map operations.\n *\n * This class implements the IMap interface using JavaScript's native Map as the\n * underlying storage mechanism for optimal performance. All mutation operations\n * create new instances rather than modifying the existing map, ensuring\n * immutability.\n *\n * **Implementation Details:**\n *\n * - Uses Map<K, V> internally for type safety and performance\n * - Implements copy-on-write semantics for efficiency\n * - Provides optional debug messaging for development\n *\n * @template K The type of the keys. Must extend MapSetKeyType.\n * @template V The type of the values.\n * @implements IMap\n * @implements Iterable\n * @internal This class should not be used directly. Use IMap.create() instead.\n */\nclass IMapClass<K extends MapSetKeyType, V>\n implements IMap<K, V>, Iterable<readonly [K, V]>\n{\n readonly #map: ReadonlyMap<K, V>;\n readonly #showNotFoundMessage: boolean;\n\n /**\n * Constructs an IMapClass instance with the given entries.\n *\n * @param iterable An iterable of key-value pairs to populate the map.\n * @param showNotFoundMessage Whether to log warning messages when operations\n * are performed on non-existent keys. Useful for debugging. Defaults to\n * false for production use.\n * @internal Use IMap.create() instead of calling this constructor directly.\n */\n constructor(\n iterable: Iterable<readonly [K, V]>,\n showNotFoundMessage: boolean = false,\n ) {\n this.#map = new Map(iterable);\n\n this.#showNotFoundMessage = showNotFoundMessage;\n }\n\n /** @inheritdoc */\n get size(): SizeType.Arr {\n return asUint32(this.#map.size);\n }\n\n /** @inheritdoc */\n has(key: K | (WidenLiteral<K> & {})): boolean {\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return this.#map.has(key as K);\n }\n\n /** @inheritdoc */\n get(key: K | (WidenLiteral<K> & {})): Optional<V> {\n if (!this.has(key)) return Optional.none;\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion, @typescript-eslint/no-non-null-assertion\n return Optional.some(this.#map.get(key as K)!);\n }\n\n /** @inheritdoc */\n every<W extends V>(\n predicate: (value: V, key: K) => value is W,\n ): this is IMap<K, W>;\n\n /** @inheritdoc */\n every(predicate: (value: V, key: K) => boolean): boolean;\n\n /** @inheritdoc */\n every(predicate: (value: V, key: K) => boolean): boolean {\n for (const [k, v] of this.entries()) {\n if (!predicate(v, k)) return false;\n }\n\n return true;\n }\n\n /** @inheritdoc */\n some(predicate: (value: V, key: K) => boolean): boolean {\n for (const [k, v] of this.entries()) {\n if (predicate(v, k)) return true;\n }\n\n return false;\n }\n\n /** @inheritdoc */\n delete(key: K): IMap<K, V> {\n if (!this.has(key)) {\n if (this.#showNotFoundMessage) {\n const keyStr = unknownToString(key);\n\n console.warn(`IMap.delete: key not found: ${keyStr}`);\n }\n\n return this;\n }\n\n return IMap.create(\n Array.from(this.#map).filter(([k]) => !Object.is(k, key)),\n );\n }\n\n /** @inheritdoc */\n set(key: K, value: V): IMap<K, V> {\n const curr = this.get(key);\n\n if (Optional.isSome(curr) && value === curr.value) return this; // has no changes\n\n if (!this.has(key)) {\n return IMap.create([...this.#map, tp(key, value)]);\n }\n\n return IMap.create(\n Array.from(this.#map, ([k, v]) => tp(k, Object.is(k, key) ? value : v)),\n );\n }\n\n /** @inheritdoc */\n update(key: K, updater: (value: V) => V): IMap<K, V> {\n const curr = this.get(key);\n\n if (Optional.isNone(curr)) {\n if (this.#showNotFoundMessage) {\n const keyStr = unknownToString(key);\n\n console.warn(`IMap.update: key not found: ${keyStr}`);\n }\n\n return this;\n }\n\n return IMap.create(\n Array.from(this.#map, ([k, v]) =>\n tp(k, Object.is(k, key) ? updater(curr.value) : v),\n ),\n );\n }\n\n /** @inheritdoc */\n withMutations(\n actions: readonly Readonly<\n | { type: 'delete'; key: K }\n | { type: 'set'; key: K; value: V }\n | { type: 'update'; key: K; updater: (value: V) => V }\n >[],\n ): IMap<K, V> {\n const mut_result = new Map<K, V>(this.#map);\n\n const updateFn = (\n action: Readonly<\n | { type: 'delete'; key: K }\n | { type: 'set'; key: K; value: V }\n | { type: 'update'; key: K; updater: (value: V) => V }\n >,\n ): void => {\n switch (action.type) {\n case 'delete':\n mut_result.delete(action.key);\n\n break;\n\n case 'set':\n mut_result.set(action.key, action.value);\n\n break;\n\n case 'update': {\n const { key } = action;\n\n const curr = mut_result.get(key);\n\n if (!mut_result.has(key) || curr === undefined) {\n if (this.#showNotFoundMessage) {\n const keyStr = unknownToString(key);\n\n console.warn(`IMap.withMutations: key not found: ${keyStr}`);\n }\n\n break;\n }\n\n mut_result.set(key, action.updater(curr));\n\n break;\n }\n }\n };\n\n for (const action of actions) {\n updateFn(action);\n }\n\n return IMap.create(mut_result);\n }\n\n /** @inheritdoc */\n map<V2>(mapFn: (value: V, key: K) => V2): IMap<K, V2> {\n return IMap.create(this.toArray().map(([k, v]) => tp(k, mapFn(v, k))));\n }\n\n /** @inheritdoc */\n mapKeys<K2 extends MapSetKeyType>(mapFn: (key: K) => K2): IMap<K2, V> {\n return IMap.create(this.toArray().map(([k, v]) => tp(mapFn(k), v)));\n }\n\n /** @inheritdoc */\n mapEntries<K2 extends MapSetKeyType, V2>(\n mapFn: (entry: readonly [K, V]) => readonly [K2, V2],\n ): IMap<K2, V2> {\n return IMap.create(this.toArray().map(mapFn));\n }\n\n /** @inheritdoc */\n forEach(callbackfn: (value: V, key: K) => void): void {\n for (const [key, value] of this.#map) {\n callbackfn(value, key);\n }\n }\n\n /**\n * @example\n *\n * ```ts\n * const entries = [\n * ['first', 1],\n * ['second', 2],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * const collected = Array.from(map);\n *\n * assert.deepStrictEqual(collected, [\n * ['first', 1],\n * ['second', 2],\n * ]);\n * ```\n *\n * @inheritdoc\n */\n [Symbol.iterator](): Iterator<readonly [K, V]> {\n return this.#map[Symbol.iterator]();\n }\n\n /** @inheritdoc */\n keys(): IterableIterator<K> {\n return this.#map.keys();\n }\n\n /** @inheritdoc */\n values(): IterableIterator<V> {\n return this.#map.values();\n }\n\n /** @inheritdoc */\n entries(): IterableIterator<readonly [K, V]> {\n return this.#map.entries();\n }\n\n /** @inheritdoc */\n toKeysArray(): readonly K[] {\n return Array.from(this.keys());\n }\n\n /** @inheritdoc */\n toValuesArray(): readonly V[] {\n return Array.from(this.values());\n }\n\n /** @inheritdoc */\n toEntriesArray(): readonly (readonly [K, V])[] {\n return Array.from(this.entries());\n }\n\n /** @inheritdoc */\n toArray(): readonly (readonly [K, V])[] {\n return Array.from(this.entries());\n }\n\n /** @inheritdoc */\n toRawMap(): ReadonlyMap<K, V> {\n return this.#map;\n }\n}\n"],"names":["IMap","Optional.isSome","Optional.none","Optional.some","Optional.isNone"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4mBO,IAAU;AAAA,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A8B;AAC5B,IAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,MAAA,EAAQ,CAAA;AAAA,EACjC;AAAA;AAAA,EAGA,cAAA,GAA+C;AAC7C,IAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,OAAA,EAAS,CAAA;AAAA,EAClC;AAAA;AAAA,EAGA,OAAA,GAAwC;AACtC,IAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,OAAA,EAAS,CAAA;AAAA,EAClC;AAAA;AAAA,EAGA,QAAA,GAA8B;AAC5B,IAAA,OAAO,IAAA,CAAK,IAAA;AAAA,EACd;AACF;;;;"}
1
+ {"version":3,"file":"imap.mjs","sources":["../../src/collections/imap.mts"],"sourcesContent":["/* eslint-disable unicorn/prefer-iterator-to-array-at-end */\nimport { type WidenLiteral } from 'ts-type-forge';\nimport { Optional, pipe } from '../functional/index.mjs';\nimport { asUint32 } from '../number/index.mjs';\nimport { tp, unknownToString } from '../others/index.mjs';\nimport { type MapSetKeyType, type SizeType } from '../types.mjs';\n\n/**\n * Interface for an immutable map with lookup operations and functional\n * programming patterns.\n *\n * This interface defines all methods and properties available on IMap\n * instances. All operations that modify the map return new IMap instances,\n * preserving immutability. The underlying implementation uses JavaScript's\n * native Map but creates copies on mutations to maintain immutability.\n *\n * **Immutability Guarantees:**\n *\n * - All mutation operations (set, delete, update) return new IMap instances\n * - Original IMap instances are never modified\n * - Safe for concurrent access and functional programming patterns\n *\n * **Performance Characteristics:**\n *\n * - get/has: O(1) average case\n * - set/delete: O(n) due to copying for immutability\n * - map/filter operations: O(n)\n * - iteration: O(n)\n *\n * @template K The type of the keys in the map. Must extend MapSetKeyType\n * (string, number, boolean, etc.)\n * @template V The type of the values in the map.\n */\ntype IMapInterface<K extends MapSetKeyType, V> = Readonly<{\n // Getting information\n\n /**\n * The number of elements in the map.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['a', 1],\n * ['b', 2],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * assert.isTrue(map.size === 2);\n * ```\n */\n size: SizeType.Arr;\n\n /**\n * Checks if a key exists in the map. Allows for wider literal types for keys\n * during checking.\n *\n * @example\n *\n * ```ts\n * const map = IMap.create<'id' | 'enabled', number | boolean>([\n * ['id', 42],\n * ['enabled', true],\n * ]);\n *\n * assert.isTrue(map.has('id'));\n *\n * assert.isFalse(map.has('missing'));\n * ```\n *\n * @param key The key to check.\n * @returns `true` if the key exists, `false` otherwise.\n */\n has: (key: K | (WidenLiteral<K> & {})) => boolean;\n\n /**\n * Retrieves the value associated with a key.\n *\n * @example\n *\n * ```ts\n * const map = IMap.create([['user', { id: 1 }]]);\n *\n * assert.deepStrictEqual(map.get('user'), Optional.some({ id: 1 }));\n *\n * assert.deepStrictEqual(map.get('missing'), Optional.none);\n * ```\n *\n * @param key The key to retrieve.\n * @returns The value associated with the key wrapped with `Optional.some`, or\n * `Optional.none` if the key does not exist.\n */\n get: (key: K | (WidenLiteral<K> & {})) => Optional<V>;\n\n // Reducing a value\n\n /**\n * Checks if all elements in the map satisfy a predicate. Also supports a\n * type predicate overload that narrows the type of values in the map if the\n * predicate returns true for all elements.\n *\n * @example\n *\n * ```ts\n * const map = IMap.create([\n * ['a', 2],\n * ['b', 4],\n * ]);\n *\n * const allEven = map.every((value) => value % 2 === 0);\n *\n * const isNarrowed = map.every((value): value is 2 | 4 => value % 2 === 0);\n *\n * assert.isTrue(allEven);\n *\n * assert.isTrue(isNarrowed);\n * ```\n *\n * @template W The narrowed type of the values.\n * @param predicate A function to test each key-value pair.\n * @returns `true` if all elements satisfy the predicate, `false` otherwise.\n */\n every: ((predicate: (value: V, key: K) => boolean) => boolean) &\n (<W extends V>(\n predicate: (value: V, key: K) => value is W,\n ) => this is IMap<K, W>);\n\n /**\n * Checks if at least one element in the map satisfies a predicate.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['alice', 3],\n * ['bob', 5],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * assert.isTrue(map.some((value) => value > 4));\n *\n * assert.isFalse(map.some((value) => value > 10));\n * ```\n *\n * @param predicate A function to test each key-value pair.\n * @returns `true` if at least one element satisfies the predicate, `false`\n * otherwise.\n */\n some: (predicate: (value: V, key: K) => boolean) => boolean;\n\n // Mutation\n\n /**\n * Deletes a key-value pair from the map.\n *\n * @example\n *\n * ```ts\n * const original = IMap.create([\n * ['a', 1],\n * ['b', 2],\n * ]);\n *\n * const withoutB = original.delete('b');\n *\n * assert.deepStrictEqual(original.get('b'), Optional.some(2));\n *\n * assert.deepStrictEqual(withoutB.get('b'), Optional.none);\n *\n * assert.isTrue(original.size === 2);\n *\n * assert.isTrue(withoutB.size === 1);\n * ```\n *\n * @param key The key to delete.\n * @returns A new IMap instance without the specified key.\n */\n delete: (key: K) => IMap<K, V>;\n\n /**\n * Sets a key-value pair in the map.\n *\n * @example\n *\n * ```ts\n * const entries = [['count', 1]] as const satisfies readonly (readonly [\n * 'count' | 'status',\n * number | string,\n * ])[];\n *\n * const base = IMap.create<'count' | 'status', number | string>(entries);\n *\n * const updated = base.set('count', 2);\n *\n * const extended = base.set('status', 'ok');\n *\n * assert.deepStrictEqual(base.get('count'), Optional.some(1));\n *\n * assert.deepStrictEqual(updated.get('count'), Optional.some(2));\n *\n * assert.deepStrictEqual(extended.get('status'), Optional.some('ok'));\n * ```\n *\n * @param key The key to set.\n * @param value The value to associate with the key.\n * @returns A new IMap instance with the specified key-value pair.\n */\n set: (key: K, value: V) => IMap<K, V>;\n\n /**\n * Updates the value associated with a key using an updater function.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['alice', 10],\n * ['bob', 8],\n * ] as const satisfies readonly (readonly [\n * 'alice' | 'bob' | 'charlie',\n * number,\n * ])[];\n *\n * const scores = IMap.create<'alice' | 'bob' | 'charlie', number>(entries);\n *\n * const boosted = scores.update('alice', (value) => value + 5);\n *\n * const unchanged = scores.update('charlie', (value) => value + 1);\n *\n * assert.deepStrictEqual(boosted.get('alice'), Optional.some(15));\n *\n * assert.deepStrictEqual(scores.get('alice'), Optional.some(10));\n *\n * assert.isTrue(unchanged === scores);\n * ```\n *\n * @param key The key whose value to update.\n * @param updater A function that takes the current value and returns the new\n * value.\n * @returns A new IMap instance with the updated value.\n */\n update: (key: K, updater: (value: V) => V) => IMap<K, V>;\n\n /**\n * Applies a series of mutations to the map.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['a', 1],\n * ['b', 2],\n * ] as const satisfies readonly (readonly ['a' | 'b' | 'c', number])[];\n *\n * const base = IMap.create<'a' | 'b' | 'c', number>(entries);\n *\n * const actions: readonly Readonly<\n * | { type: 'set'; key: 'c'; value: number }\n * | { type: 'update'; key: 'b'; updater: (value: number) => number }\n * | { type: 'delete'; key: 'a' }\n * >[] = [\n * { type: 'set', key: 'c', value: 3 },\n * { type: 'update', key: 'b', updater: (value) => value * 10 },\n * { type: 'delete', key: 'a' },\n * ] as const;\n *\n * const mutated = base.withMutations(actions);\n *\n * assert.deepStrictEqual(mutated.get('c'), Optional.some(3));\n *\n * assert.deepStrictEqual(mutated.get('b'), Optional.some(20));\n *\n * assert.deepStrictEqual(mutated.get('a'), Optional.none);\n *\n * assert.deepStrictEqual(base.get('b'), Optional.some(2));\n * ```\n *\n * @param actions An array of mutation actions (delete, set, or update).\n * @returns A new IMap instance with all mutations applied.\n */\n withMutations: (\n actions: readonly Readonly<\n | { type: 'delete'; key: K }\n | { type: 'set'; key: K; value: V }\n | { type: 'update'; key: K; updater: (value: V) => V }\n >[],\n ) => IMap<K, V>;\n\n // Sequence algorithms\n\n /**\n * Maps the values of the map to new values.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['a', 1],\n * ['b', 2],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * const doubled = map.map((value) => value * 2);\n *\n * assert.deepStrictEqual(Array.from(doubled), [\n * ['a', 2],\n * ['b', 4],\n * ]);\n * ```\n *\n * @template V2 The type of the new values.\n * @param mapFn A function that maps a value and key to a new value.\n * @returns A new IMap instance with mapped values.\n */\n map: <V2>(mapFn: (value: V, key: K) => V2) => IMap<K, V2>;\n\n /**\n * Maps the keys of the map to new keys.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['first', 1],\n * ['second', 2],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * const upperKeys = map.mapKeys((key) => key.toUpperCase());\n *\n * assert.deepStrictEqual(Array.from(upperKeys), [\n * ['FIRST', 1],\n * ['SECOND', 2],\n * ]);\n * ```\n *\n * @template K2 The type of the new keys.\n * @param mapFn A function that maps a key to a new key.\n * @returns A new IMap instance with mapped keys and original values.\n */\n mapKeys: <K2 extends MapSetKeyType>(mapFn: (key: K) => K2) => IMap<K2, V>;\n\n /**\n * Maps the entries (key-value pairs) of the map to new entries.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['a', 1],\n * ['b', 2],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * const swapped = map.mapEntries(\n * ([key, value]) => [value, key] satisfies readonly [number, string],\n * );\n *\n * assert.deepStrictEqual(Array.from(swapped), [\n * [1, 'a'],\n * [2, 'b'],\n * ]);\n * ```\n *\n * @template K2 The type of the new keys in the entries.\n * @template V2 The type of the new values in the entries.\n * @param mapFn A function that maps an entry to a new entry.\n * @returns A new IMap instance with mapped entries.\n */\n mapEntries: <K2 extends MapSetKeyType, V2>(\n mapFn: (entry: readonly [K, V]) => readonly [K2, V2],\n ) => IMap<K2, V2>;\n\n // Side effects\n\n /**\n * Executes a callback function for each key-value pair in the map.\n *\n * @example\n *\n * ```ts\n * const map = IMap.create([\n * ['a', 1],\n * ['b', 2],\n * ]);\n *\n * const mut_entries: (readonly [string, number])[] = [];\n *\n * map.forEach((value, key) => {\n * mut_entries.push([key, value]);\n * });\n *\n * assert.deepStrictEqual(mut_entries, [\n * ['a', 1],\n * ['b', 2],\n * ]);\n * ```\n *\n * @param callbackfn A function to execute for each element.\n */\n forEach: (callbackfn: (value: V, key: K) => void) => void;\n\n // Iterators\n\n /**\n * Returns an iterator for the keys in the map.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['a', 1],\n * ['b', 2],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * const keys = Array.from(map.keys());\n *\n * assert.deepStrictEqual(keys, ['a', 'b']);\n * ```\n *\n * @returns An iterable iterator of keys.\n */\n keys: () => IterableIterator<K>;\n\n /**\n * Returns an iterator for the values in the map.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['a', 1],\n * ['b', 2],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * const values = Array.from(map.values());\n *\n * assert.deepStrictEqual(values, [1, 2]);\n * ```\n *\n * @returns An iterable iterator of values.\n */\n values: () => IterableIterator<V>;\n\n /**\n * Returns an iterator for the entries (key-value pairs) in the map.\n *\n * @example\n *\n * ```ts\n * const map = IMap.create([\n * ['a', 1],\n * ['b', 2],\n * ]);\n *\n * const entries = Array.from(map.entries());\n *\n * assert.deepStrictEqual(entries, [\n * ['a', 1],\n * ['b', 2],\n * ]);\n * ```\n *\n * @returns An iterable iterator of entries.\n */\n entries: () => IterableIterator<readonly [K, V]>;\n\n // Conversion\n\n /**\n * Converts the keys of the map to an array.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['x', 10],\n * ['y', 20],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * assert.deepStrictEqual(map.toKeysArray(), ['x', 'y']);\n * ```\n *\n * @returns A readonly array of keys.\n */\n toKeysArray: () => readonly K[];\n\n /**\n * Converts the values of the map to an array.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['x', 10],\n * ['y', 20],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * assert.deepStrictEqual(map.toValuesArray(), [10, 20]);\n * ```\n *\n * @returns A readonly array of values.\n */\n toValuesArray: () => readonly V[];\n\n /**\n * Converts the entries (key-value pairs) of the map to an array.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['a', 1],\n * ['b', 2],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * assert.deepStrictEqual(map.toEntriesArray(), [\n * ['a', 1],\n * ['b', 2],\n * ]);\n * ```\n *\n * @returns A readonly array of entries.\n */\n toEntriesArray: () => readonly (readonly [K, V])[];\n\n /**\n * Converts the map to an array of entries (key-value pairs). Alias for\n * `toEntriesArray`.\n *\n * @example\n *\n * ```ts\n * const entries = [\n * ['k1', 'v1'],\n * ['k2', 'v2'],\n * ] as const satisfies readonly FixedLengthTuple<2, string>[];\n *\n * const map = IMap.create(entries);\n *\n * assert.deepStrictEqual(map.toArray(), [\n * ['k1', 'v1'],\n * ['k2', 'v2'],\n * ]);\n * ```\n *\n * @returns A readonly array of entries.\n */\n toArray: () => readonly (readonly [K, V])[];\n\n /**\n * Returns the underlying readonly JavaScript Map.\n *\n * @example\n *\n * ```ts\n * const entries = [['key', 1]] as const satisfies readonly (readonly [\n * string,\n * number,\n * ])[];\n *\n * const map = IMap.create(entries);\n *\n * const raw = map.toRawMap();\n *\n * assert.isTrue(isMap(raw));\n *\n * assert.isTrue(raw.get('key') === 1);\n * ```\n *\n * @returns The raw ReadonlyMap instance.\n */\n toRawMap: () => ReadonlyMap<K, V>;\n}>;\n\n/**\n * Represents an immutable map with high-performance operations and functional\n * programming support.\n *\n * IMap is a persistent data structure that provides all the functionality of\n * JavaScript's Map while maintaining immutability. All operations that would\n * normally mutate the map instead return new IMap instances, making it safe for\n * functional programming and concurrent access.\n *\n * **Key Features:**\n *\n * - **Immutable**: All mutation operations return new instances\n * - **Type Safe**: Full TypeScript support with generic key/value types\n * - **Iterable**: Implements standard JavaScript iteration protocols\n * - **Functional**: Rich API for map, filter, reduce-style operations\n *\n * **When to Use:**\n *\n * - State management in functional applications\n * - Caching with immutable guarantees\n * - Data structures that need to be shared across components\n * - When you need Map functionality but want immutability\n *\n * @template K The type of the keys in the map. Must extend MapSetKeyType.\n * @template V The type of the values in the map.\n */\nexport type IMap<K extends MapSetKeyType, V> = Iterable<readonly [K, V]> &\n IMapInterface<K, V>;\n\n/** Provides utility functions for IMap. */\nexport namespace IMap {\n /**\n * Creates a new IMap instance from an iterable of key-value pairs.\n *\n * This factory function accepts any iterable of [key, value] tuples,\n * including arrays, JavaScript Maps, other IMaps, or custom iterables. The\n * resulting IMap will contain all the entries from the input iterable.\n *\n * **Performance:** O(n) where n is the number of entries in the iterable.\n *\n * @example\n *\n * ```ts\n * const map = IMap.create<string, number | string>([\n * ['id', 1],\n * ['status', 'active'],\n * ]);\n *\n * assert.isTrue(map.size === 2);\n *\n * assert.deepStrictEqual(map.get('status'), Optional.some('active'));\n * ```\n *\n * @template K The type of the keys. Must extend MapSetKeyType.\n * @template V The type of the values.\n * @param iterable An iterable of key-value pairs (e.g., Array, Map, IMap,\n * etc.)\n * @returns A new IMap instance containing all entries from the iterable.\n */\n export const create = <K extends MapSetKeyType, V>(\n iterable: Iterable<readonly [K, V]>,\n ): IMap<K, V> => new IMapClass<K, V>(iterable);\n\n /**\n * Checks if two IMap instances are structurally equal.\n *\n * Two IMaps are considered equal if they have the same size and contain\n * exactly the same key-value pairs. The order of entries does not matter for\n * equality comparison. Values are compared using JavaScript's `===`\n * operator.\n *\n * **Performance:** O(n) where n is the size of the smaller map.\n *\n * @example\n *\n * ```ts\n * const first = IMap.create<'a' | 'b', number>([\n * ['a', 1],\n * ['b', 2],\n * ]);\n *\n * const second = IMap.create<'a' | 'b', number>([\n * ['b', 2],\n * ['a', 1],\n * ]);\n *\n * const third = IMap.create<'a' | 'b', number>([\n * ['a', 1],\n * ['b', 3],\n * ]);\n *\n * assert.isTrue(IMap.equal(first, second));\n *\n * assert.isFalse(IMap.equal(first, third));\n * ```\n *\n * @template K The type of the keys.\n * @template V The type of the values.\n * @param a The first IMap instance to compare.\n * @param b The second IMap instance to compare.\n * @returns `true` if the maps contain exactly the same key-value pairs,\n * `false` otherwise.\n */\n export const equal = <K extends MapSetKeyType, V>(\n a: IMap<K, V>,\n b: IMap<K, V>,\n ): boolean =>\n a.size === b.size &&\n a.every(\n (v, k) =>\n pipe(b.get(k)).map((v2) => Optional.isSome(v2) && v2.value === v).value,\n );\n}\n\n/**\n * Internal class implementation for IMap providing immutable map operations.\n *\n * This class implements the IMap interface using JavaScript's native Map as the\n * underlying storage mechanism for optimal performance. All mutation operations\n * create new instances rather than modifying the existing map, ensuring\n * immutability.\n *\n * **Implementation Details:**\n *\n * - Uses Map<K, V> internally for type safety and performance\n * - Implements copy-on-write semantics for efficiency\n * - Provides optional debug messaging for development\n *\n * @template K The type of the keys. Must extend MapSetKeyType.\n * @template V The type of the values.\n * @implements IMap\n * @implements Iterable\n * @internal This class should not be used directly. Use IMap.create() instead.\n */\nclass IMapClass<K extends MapSetKeyType, V>\n implements IMap<K, V>, Iterable<readonly [K, V]>\n{\n readonly #map: ReadonlyMap<K, V>;\n readonly #showNotFoundMessage: boolean;\n\n /**\n * Constructs an IMapClass instance with the given entries.\n *\n * @param iterable An iterable of key-value pairs to populate the map.\n * @param showNotFoundMessage Whether to log warning messages when operations\n * are performed on non-existent keys. Useful for debugging. Defaults to\n * false for production use.\n * @internal Use IMap.create() instead of calling this constructor directly.\n */\n constructor(\n iterable: Iterable<readonly [K, V]>,\n showNotFoundMessage: boolean = false,\n ) {\n this.#map = new Map(iterable);\n\n this.#showNotFoundMessage = showNotFoundMessage;\n }\n\n /** @inheritdoc */\n get size(): SizeType.Arr {\n return asUint32(this.#map.size);\n }\n\n /** @inheritdoc */\n has(key: K | (WidenLiteral<K> & {})): boolean {\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return this.#map.has(key as K);\n }\n\n /** @inheritdoc */\n get(key: K | (WidenLiteral<K> & {})): Optional<V> {\n if (!this.has(key)) return Optional.none;\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion, @typescript-eslint/no-non-null-assertion\n return Optional.some(this.#map.get(key as K)!);\n }\n\n /** @inheritdoc */\n every<W extends V>(\n predicate: (value: V, key: K) => value is W,\n ): this is IMap<K, W>;\n\n /** @inheritdoc */\n every(predicate: (value: V, key: K) => boolean): boolean;\n\n /** @inheritdoc */\n every(predicate: (value: V, key: K) => boolean): boolean {\n for (const [k, v] of this.entries()) {\n if (!predicate(v, k)) return false;\n }\n\n return true;\n }\n\n /** @inheritdoc */\n some(predicate: (value: V, key: K) => boolean): boolean {\n for (const [k, v] of this.entries()) {\n if (predicate(v, k)) return true;\n }\n\n return false;\n }\n\n /** @inheritdoc */\n delete(key: K): IMap<K, V> {\n if (!this.has(key)) {\n if (this.#showNotFoundMessage) {\n const keyStr = unknownToString(key);\n\n console.warn(`IMap.delete: key not found: ${keyStr}`);\n }\n\n return this;\n }\n\n return IMap.create(\n Array.from(this.#map).filter(([k]) => !Object.is(k, key)),\n );\n }\n\n /** @inheritdoc */\n set(key: K, value: V): IMap<K, V> {\n const curr = this.get(key);\n\n if (Optional.isSome(curr) && value === curr.value) return this; // has no changes\n\n if (!this.has(key)) {\n return IMap.create([...this.#map, tp(key, value)]);\n }\n\n return IMap.create(\n Array.from(this.#map, ([k, v]) => tp(k, Object.is(k, key) ? value : v)),\n );\n }\n\n /** @inheritdoc */\n update(key: K, updater: (value: V) => V): IMap<K, V> {\n const curr = this.get(key);\n\n if (Optional.isNone(curr)) {\n if (this.#showNotFoundMessage) {\n const keyStr = unknownToString(key);\n\n console.warn(`IMap.update: key not found: ${keyStr}`);\n }\n\n return this;\n }\n\n return IMap.create(\n Array.from(this.#map, ([k, v]) =>\n tp(k, Object.is(k, key) ? updater(curr.value) : v),\n ),\n );\n }\n\n /** @inheritdoc */\n withMutations(\n actions: readonly Readonly<\n | { type: 'delete'; key: K }\n | { type: 'set'; key: K; value: V }\n | { type: 'update'; key: K; updater: (value: V) => V }\n >[],\n ): IMap<K, V> {\n const mut_result = new Map<K, V>(this.#map);\n\n const updateFn = (\n action: Readonly<\n | { type: 'delete'; key: K }\n | { type: 'set'; key: K; value: V }\n | { type: 'update'; key: K; updater: (value: V) => V }\n >,\n ): void => {\n switch (action.type) {\n case 'delete':\n mut_result.delete(action.key);\n\n break;\n\n case 'set':\n mut_result.set(action.key, action.value);\n\n break;\n\n case 'update': {\n const { key } = action;\n\n const curr = mut_result.get(key);\n\n if (curr === undefined || !mut_result.has(key)) {\n if (this.#showNotFoundMessage) {\n const keyStr = unknownToString(key);\n\n console.warn(`IMap.withMutations: key not found: ${keyStr}`);\n }\n\n break;\n }\n\n mut_result.set(key, action.updater(curr));\n\n break;\n }\n }\n };\n\n for (const action of actions) {\n updateFn(action);\n }\n\n return IMap.create(mut_result);\n }\n\n /** @inheritdoc */\n map<V2>(mapFn: (value: V, key: K) => V2): IMap<K, V2> {\n return IMap.create(this.toArray().map(([k, v]) => tp(k, mapFn(v, k))));\n }\n\n /** @inheritdoc */\n mapKeys<K2 extends MapSetKeyType>(mapFn: (key: K) => K2): IMap<K2, V> {\n return IMap.create(this.toArray().map(([k, v]) => tp(mapFn(k), v)));\n }\n\n /** @inheritdoc */\n mapEntries<K2 extends MapSetKeyType, V2>(\n mapFn: (entry: readonly [K, V]) => readonly [K2, V2],\n ): IMap<K2, V2> {\n return IMap.create(this.toArray().map(mapFn));\n }\n\n /** @inheritdoc */\n forEach(callbackfn: (value: V, key: K) => void): void {\n for (const [key, value] of this.#map) {\n callbackfn(value, key);\n }\n }\n\n /**\n * @example\n *\n * ```ts\n * const entries = [\n * ['first', 1],\n * ['second', 2],\n * ] as const satisfies readonly (readonly [string, number])[];\n *\n * const map = IMap.create(entries);\n *\n * const collected = Array.from(map);\n *\n * assert.deepStrictEqual(collected, [\n * ['first', 1],\n * ['second', 2],\n * ]);\n * ```\n *\n * @inheritdoc\n */\n [Symbol.iterator](): Iterator<readonly [K, V]> {\n return this.#map[Symbol.iterator]();\n }\n\n /** @inheritdoc */\n keys(): IterableIterator<K> {\n return this.#map.keys();\n }\n\n /** @inheritdoc */\n values(): IterableIterator<V> {\n return this.#map.values();\n }\n\n /** @inheritdoc */\n entries(): IterableIterator<readonly [K, V]> {\n return this.#map.entries();\n }\n\n /** @inheritdoc */\n toKeysArray(): readonly K[] {\n return Array.from(this.keys());\n }\n\n /** @inheritdoc */\n toValuesArray(): readonly V[] {\n return Array.from(this.values());\n }\n\n /** @inheritdoc */\n toEntriesArray(): readonly (readonly [K, V])[] {\n return Array.from(this.entries());\n }\n\n /** @inheritdoc */\n toArray(): readonly (readonly [K, V])[] {\n return Array.from(this.entries());\n }\n\n /** @inheritdoc */\n toRawMap(): ReadonlyMap<K, V> {\n return this.#map;\n }\n}\n"],"names":["IMap","Optional.isSome","Optional.none","Optional.some","Optional.isNone"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4mBO,IAAU;AAAA,CAAV,CAAUA,KAAAA,KAAV;AA6BE,EAAMA,MAAA,MAAA,GAAS,CACpB,QAAA,KACe,IAAI,UAAgB,QAAQ,CAAA;AA0CtC,EAAMA,KAAAA,CAAA,QAAQ,CACnB,CAAA,EACA,MAEA,CAAA,CAAE,IAAA,KAAS,CAAA,CAAE,IAAA,IACb,CAAA,CAAE,KAAA;AAAA,IACA,CAAC,CAAA,EAAG,CAAA,KACF,KAAK,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,CAAA,CAAE,IAAI,CAAC,EAAA,KAAOC,MAAS,CAAO,EAAE,KAAK,EAAA,CAAG,KAAA,KAAU,CAAC,CAAA,CAAE;AAAA,GACtE;AAAA,CAAA,EAjFa,IAAA,KAAA,IAAA,GAAA,EAAA,CAAA,CAAA;AAwGjB,MAAM,SAAA,CAEN;AAAA,EACW,IAAA;AAAA,EACA,oBAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWT,WAAA,CACE,QAAA,EACA,mBAA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AAE,MAAM,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;AAcpD;;;;;GAKG;AACH,KAAK,0BAA0B,CAC7B,IAAI,SAAS,WAAW,EACxB,CAAC,SAAS,aAAa,IAEvB,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,SAAS,IAAI,GAC1C,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC,GACxB,KAAK,CAAC;AA4BZ;;;;;;GAMG;AACH,KAAK,aAAa,CAAC,CAAC,SAAS,WAAW,IAAI,MAAM,SAAS,CAAC,GACxD,KAAK,GACL,MAAM,SAAS,CAAC,GACd,KAAK,GACL,MAAM,SAAS,CAAC,GACd,KAAK,GACL,IAAI,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"match.mjs","sources":["../../src/functional/match.mts"],"sourcesContent":["import {\n type ReadonlyRecord,\n type RelaxedExclude,\n type TypeEq,\n type UnknownRecord,\n type ValueOf,\n} from 'ts-type-forge';\nimport { expectType } from '../expect-type.mjs';\nimport { keyIsIn } from '../guard/index.mjs';\n\n/**\n * Type-safe pattern matching function for string-based discriminated unions.\n *\n * Provides compile-time guarantees for exhaustive case handling when working\n * with literal string unions. Automatically enforces completeness checking when\n * all cases are covered, and requires a default value when cases are\n * incomplete.\n *\n * ## Key Features:\n *\n * - **Exhaustive Matching**: When all cases of a literal union are handled, no\n * default value is needed\n * - **Partial Matching**: When cases are incomplete or working with general\n * string types, a default value is required\n * - **Type Safety**: Prevents extra cases and ensures only valid keys are used\n * - **Strict Property Checking**: Rejects objects with unexpected properties\n *\n * @example\n *\n * ```ts\n * type Status = 'draft' | 'review' | 'published';\n *\n * const status: Status = 'draft';\n *\n * const message = match<\n * Status,\n * Readonly<{ draft: string; review: string; published: string }>\n * >(status, {\n * draft: 'Work in progress',\n * review: 'Awaiting feedback',\n * published: 'Complete',\n * });\n *\n * assert.isTrue(message === 'Work in progress');\n * ```\n *\n * @param target - The value to match against\n * @param cases - Object mapping possible values to their corresponding results\n * @param defaultValue - Fallback value (required when not all cases are\n * covered)\n * @returns The matched result or default value\n */\nexport function match<\n const Case extends string,\n const R extends ReadonlyRecord<Case, unknown>,\n>(target: Case, cases: StrictPropertyCheck<R, Case>): R[Case];\n\nexport function match<\n const Case extends string,\n const R extends UnknownRecord,\n const D,\n>(\n target: Case,\n cases: StrictPropertyCheck<R, Case>,\n defaultValue: IsLiteralUnionFullyCovered<Case, R> extends true ? never : D,\n): ValueOf<R> | D;\n\nexport function match<\n const Case extends string,\n const R extends UnknownRecord,\n const D,\n>(\n ...args:\n | readonly [target: Case, cases: R]\n | readonly [target: Case, cases: R, defaultValue: D]\n): ValueOf<R> | D {\n switch (args.length) {\n case 2: {\n const [target, cases] = args;\n\n return cases[target];\n }\n\n case 3: {\n const [target, cases, defaultValue] = args;\n\n return keyIsIn(target, cases) ? cases[target] : defaultValue;\n }\n }\n}\n\n/**\n * @template T The object type to check.\n * @template ExpectedKeys The union of string literal types representing the\n * allowed keys.\n * @internal\n * Helper type to ensure that an object `T` only contains keys specified in `ExpectedKeys`.\n * If `T` has any keys not in `ExpectedKeys`, this type resolves to `never`.\n */\ntype StrictPropertyCheck<T, ExpectedKeys extends PropertyKey> =\n RelaxedExclude<keyof T, ExpectedKeys> extends never ? T : never;\n\n/**\n * @template Case A union of string literal types representing the possible\n * cases.\n * @template R A record type.\n * @internal\n * Helper type to check if all cases in `Case` union are fully covered by keys in `R`.\n * This checks bidirectional coverage: all Case members are in R, and no extra keys.\n */\ntype AllCasesCovered<Case extends PropertyKey, R> =\n TypeEq<Case, keyof R> extends true ? true : false;\n\nexpectType<AllCasesCovered<'a' | 'b', Readonly<{ a: 1; b: 2 }>>, true>('=');\n\nexpectType<AllCasesCovered<'a' | 'b' | 'c', Readonly<{ a: 1; b: 2 }>>, false>(\n '=',\n);\n\nexpectType<AllCasesCovered<'a' | 'b', Readonly<{ a: 1; b: 2; c: 3 }>>, false>(\n '=',\n);\n\nexpectType<AllCasesCovered<string, Record<string, string>>, true>('=');\n\n/**\n * @template Case A union of string literal types.\n * @template R A record type.\n * @internal\n * Helper type to check if Case is a literal union type and all cases are covered.\n */\ntype IsLiteralUnionFullyCovered<\n Case extends PropertyKey,\n R extends UnknownRecord,\n> =\n TypeEq<IsLiteralType<Case>, true> extends true\n ? AllCasesCovered<Case, R>\n : false;\n\nexpectType<\n IsLiteralUnionFullyCovered<'a' | 'b', Readonly<{ a: 1; b: 2 }>>,\n true\n>('=');\n\nexpectType<\n IsLiteralUnionFullyCovered<'a' | 'b' | 'c', Readonly<{ a: 1; b: 2 }>>,\n false\n>('=');\n\nexpectType<\n IsLiteralUnionFullyCovered<'a' | 'b', Readonly<{ a: 1; b: 2; c: 3 }>>,\n false\n>('=');\n\nexpectType<IsLiteralUnionFullyCovered<string, Record<string, string>>, false>(\n '=',\n);\n\nexpectType<\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n IsLiteralUnionFullyCovered<'a' | 'b' | string, Readonly<{ a: 1; b: 2 }>>,\n false\n>('=');\n\n/**\n * @template T The PropertyKey type to check.\n * @returns `true` if `T` is a literal type, `false` otherwise.\n * @internal\n * Helper type to determine if a given PropertyKey `T` is a literal type (e.g., 'a', 1)\n * or a general type (e.g., string, number).\n */\ntype IsLiteralType<T extends PropertyKey> = string extends T\n ? false\n : number extends T\n ? false\n : symbol extends T\n ? false\n : true;\n\nexpectType<IsLiteralType<'a' | 'b'>, true>('=');\n\nexpectType<IsLiteralType<'a'>, true>('=');\n\nexpectType<IsLiteralType<string>, false>('=');\n\nexpectType<IsLiteralType<number>, false>('=');\n\nexpectType<IsLiteralType<1>, true>('=');\n\nexpectType<IsLiteralType<number | 'aa'>, false>('=');\n\nexpectType<IsLiteralType<'aa' | 32>, true>('=');\n"],"names":[],"mappings":";;AAmEO,SAAS,SAKX,IAAA,EAGa;AAChB,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,MAAA,EAAQ,KAAK,CAAA,GAAI,IAAA;AAExB,MAAA,OAAO,MAAM,MAAM,CAAA;AAAA,IAAA;AACrB,IAEA,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,MAAA,EAAQ,KAAA,EAAO,YAAY,CAAA,GAAI,IAAA;AAEtC,MAAA,OAAO,QAAQ,MAAA,EAAQ,KAAK,CAAA,GAAI,KAAA,CAAM,MAAM,CAAA,GAAI,YAAA;AAAA,IAAA;AAClD;AAEJ;;;;"}
1
+ {"version":3,"file":"match.mjs","sources":["../../src/functional/match.mts"],"sourcesContent":["import {\n type ReadonlyRecord,\n type RelaxedExclude,\n type TypeEq,\n type UnknownRecord,\n type ValueOf,\n} from 'ts-type-forge';\nimport { expectType } from '../expect-type.mjs';\nimport { keyIsIn } from '../guard/index.mjs';\n\n/**\n * Type-safe pattern matching function for string-based discriminated unions.\n *\n * Provides compile-time guarantees for exhaustive case handling when working\n * with literal string unions. Automatically enforces completeness checking when\n * all cases are covered, and requires a default value when cases are\n * incomplete.\n *\n * ## Key Features:\n *\n * - **Exhaustive Matching**: When all cases of a literal union are handled, no\n * default value is needed\n * - **Partial Matching**: When cases are incomplete or working with general\n * string types, a default value is required\n * - **Type Safety**: Prevents extra cases and ensures only valid keys are used\n * - **Strict Property Checking**: Rejects objects with unexpected properties\n *\n * @example\n *\n * ```ts\n * type Status = 'draft' | 'review' | 'published';\n *\n * const status: Status = 'draft';\n *\n * const message = match<\n * Status,\n * Readonly<{ draft: string; review: string; published: string }>\n * >(status, {\n * draft: 'Work in progress',\n * review: 'Awaiting feedback',\n * published: 'Complete',\n * });\n *\n * assert.isTrue(message === 'Work in progress');\n * ```\n *\n * @param target - The value to match against\n * @param cases - Object mapping possible values to their corresponding results\n * @param defaultValue - Fallback value (required when not all cases are\n * covered)\n * @returns The matched result or default value\n */\nexport function match<\n const Case extends string,\n const R extends ReadonlyRecord<Case, unknown>,\n>(target: Case, cases: StrictPropertyCheck<R, Case>): R[Case];\n\nexport function match<\n const Case extends string,\n const R extends UnknownRecord,\n const D,\n>(\n target: Case,\n cases: StrictPropertyCheck<R, Case>,\n defaultValue: IsLiteralUnionFullyCovered<Case, R> extends true ? never : D,\n): ValueOf<R> | D;\n\nexport function match<\n const Case extends string,\n const R extends UnknownRecord,\n const D,\n>(\n ...args:\n | readonly [target: Case, cases: R]\n | readonly [target: Case, cases: R, defaultValue: D]\n): ValueOf<R> | D {\n switch (args.length) {\n case 2: {\n const [target, cases] = args;\n\n return cases[target];\n }\n\n case 3: {\n const [target, cases, defaultValue] = args;\n\n return keyIsIn(target, cases) ? cases[target] : defaultValue;\n }\n }\n}\n\n/**\n * @template T The object type to check.\n * @template ExpectedKeys The union of string literal types representing the\n * allowed keys.\n * @internal\n * Helper type to ensure that an object `T` only contains keys specified in `ExpectedKeys`.\n * If `T` has any keys not in `ExpectedKeys`, this type resolves to `never`.\n */\ntype StrictPropertyCheck<T, ExpectedKeys extends PropertyKey> =\n RelaxedExclude<keyof T, ExpectedKeys> extends never ? T : never;\n\n/**\n * @template Case A union of string literal types representing the possible\n * cases.\n * @template R A record type.\n * @internal\n * Helper type to check if all cases in `Case` union are fully covered by keys in `R`.\n * This checks bidirectional coverage: all Case members are in R, and no extra keys.\n */\ntype AllCasesCovered<Case extends PropertyKey, R> =\n TypeEq<Case, keyof R> extends true ? true : false;\n\nexpectType<AllCasesCovered<'a' | 'b', Readonly<{ a: 1; b: 2 }>>, true>('=');\n\nexpectType<AllCasesCovered<'a' | 'b' | 'c', Readonly<{ a: 1; b: 2 }>>, false>(\n '=',\n);\n\nexpectType<AllCasesCovered<'a' | 'b', Readonly<{ a: 1; b: 2; c: 3 }>>, false>(\n '=',\n);\n\nexpectType<AllCasesCovered<string, ReadonlyRecord<string, string>>, true>('=');\n\n/**\n * @template Case A union of string literal types.\n * @template R A record type.\n * @internal\n * Helper type to check if Case is a literal union type and all cases are covered.\n */\ntype IsLiteralUnionFullyCovered<\n Case extends PropertyKey,\n R extends UnknownRecord,\n> =\n TypeEq<IsLiteralType<Case>, true> extends true\n ? AllCasesCovered<Case, R>\n : false;\n\nexpectType<\n IsLiteralUnionFullyCovered<'a' | 'b', Readonly<{ a: 1; b: 2 }>>,\n true\n>('=');\n\nexpectType<\n IsLiteralUnionFullyCovered<'a' | 'b' | 'c', Readonly<{ a: 1; b: 2 }>>,\n false\n>('=');\n\nexpectType<\n IsLiteralUnionFullyCovered<'a' | 'b', Readonly<{ a: 1; b: 2; c: 3 }>>,\n false\n>('=');\n\nexpectType<\n IsLiteralUnionFullyCovered<string, ReadonlyRecord<string, string>>,\n false\n>('=');\n\nexpectType<\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n IsLiteralUnionFullyCovered<'a' | 'b' | string, Readonly<{ a: 1; b: 2 }>>,\n false\n>('=');\n\n/**\n * @template T The PropertyKey type to check.\n * @returns `true` if `T` is a literal type, `false` otherwise.\n * @internal\n * Helper type to determine if a given PropertyKey `T` is a literal type (e.g., 'a', 1)\n * or a general type (e.g., string, number).\n */\ntype IsLiteralType<T extends PropertyKey> = string extends T\n ? false\n : number extends T\n ? false\n : symbol extends T\n ? false\n : true;\n\nexpectType<IsLiteralType<'a' | 'b'>, true>('=');\n\nexpectType<IsLiteralType<'a'>, true>('=');\n\nexpectType<IsLiteralType<string>, false>('=');\n\nexpectType<IsLiteralType<number>, false>('=');\n\nexpectType<IsLiteralType<1>, true>('=');\n\nexpectType<IsLiteralType<number | 'aa'>, false>('=');\n\nexpectType<IsLiteralType<'aa' | 32>, true>('=');\n"],"names":[],"mappings":";;AAmEO,SAAS,SAKX,IAAA,EAGa;AAChB,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,MAAA,EAAQ,KAAK,CAAA,GAAI,IAAA;AAExB,MAAA,OAAO,MAAM,MAAM,CAAA;AAAA,IAAA;AACrB,IAEA,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,MAAA,EAAQ,KAAA,EAAO,YAAY,CAAA,GAAI,IAAA;AAEtC,MAAA,OAAO,QAAQ,MAAA,EAAQ,KAAK,CAAA,GAAI,KAAA,CAAM,MAAM,CAAA,GAAI,YAAA;AAAA,IAAA;AAClD;AAEJ;;;;"}
@@ -241,7 +241,7 @@ export declare const Int: {
241
241
  * @param b - The divisor (must be non-zero)
242
242
  * @returns The floored quotient as an `Int`
243
243
  */
244
- readonly div: (x: import("ts-type-forge").WithSmallInt<TtfImported_Int>, y: -40 | -39 | -38 | -37 | -36 | -35 | -34 | -33 | -32 | -31 | -30 | -29 | -28 | -27 | -26 | -25 | -24 | -23 | -22 | -21 | -20 | -19 | -18 | -17 | -16 | -15 | -14 | -13 | -12 | -11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | import("ts-type-forge").NormalizeBrandUnion<number & {
244
+ readonly div: (x: import("ts-type-forge").WithSmallInt<TtfImported_Int>, y: import("ts-type-forge").RelaxedExclude<-40 | -39 | -38 | -37 | -36 | -35 | -34 | -33 | -32 | -31 | -30 | -29 | -28 | -27 | -26 | -25 | -24 | -23 | -22 | -21 | -20 | -19 | -18 | -17 | -16 | -15 | -14 | -13 | -12 | -11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39, 0> | import("ts-type-forge").NormalizeBrandUnion<number & {
245
245
  readonly "!=0": true;
246
246
  readonly Finite: true;
247
247
  readonly Int: true;
@@ -146,7 +146,7 @@ export declare const Int16: {
146
146
  * @param b - The divisor (must be non-zero)
147
147
  * @returns The floored quotient as an `Int16`
148
148
  */
149
- readonly div: (x: import("ts-type-forge").WithSmallInt<TtfImported_Int16>, y: -40 | -39 | -38 | -37 | -36 | -35 | -34 | -33 | -32 | -31 | -30 | -29 | -28 | -27 | -26 | -25 | -24 | -23 | -22 | -21 | -20 | -19 | -18 | -17 | -16 | -15 | -14 | -13 | -12 | -11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | import("ts-type-forge").NormalizeBrandUnion<number & {
149
+ readonly div: (x: import("ts-type-forge").WithSmallInt<TtfImported_Int16>, y: import("ts-type-forge").RelaxedExclude<-40 | -39 | -38 | -37 | -36 | -35 | -34 | -33 | -32 | -31 | -30 | -29 | -28 | -27 | -26 | -25 | -24 | -23 | -22 | -21 | -20 | -19 | -18 | -17 | -16 | -15 | -14 | -13 | -12 | -11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39, 0> | import("ts-type-forge").NormalizeBrandUnion<number & {
150
150
  readonly "!=0": true;
151
151
  readonly "< 2^15": true;
152
152
  readonly "< 2^16": true;
@@ -142,7 +142,7 @@ export declare const Int32: {
142
142
  * @param b - The divisor (must be non-zero)
143
143
  * @returns The floored quotient as an `Int32`
144
144
  */
145
- readonly div: (x: import("ts-type-forge").WithSmallInt<TtfImported_Int32>, y: -40 | -39 | -38 | -37 | -36 | -35 | -34 | -33 | -32 | -31 | -30 | -29 | -28 | -27 | -26 | -25 | -24 | -23 | -22 | -21 | -20 | -19 | -18 | -17 | -16 | -15 | -14 | -13 | -12 | -11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | import("ts-type-forge").NormalizeBrandUnion<number & {
145
+ readonly div: (x: import("ts-type-forge").WithSmallInt<TtfImported_Int32>, y: import("ts-type-forge").RelaxedExclude<-40 | -39 | -38 | -37 | -36 | -35 | -34 | -33 | -32 | -31 | -30 | -29 | -28 | -27 | -26 | -25 | -24 | -23 | -22 | -21 | -20 | -19 | -18 | -17 | -16 | -15 | -14 | -13 | -12 | -11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39, 0> | import("ts-type-forge").NormalizeBrandUnion<number & {
146
146
  readonly "!=0": true;
147
147
  readonly "< 2^31": true;
148
148
  readonly "< 2^32": true;
@@ -143,7 +143,7 @@ export declare const NonNegativeInt16: {
143
143
  * @param b - The divisor (must be non-zero)
144
144
  * @returns The floored quotient as a `NonNegativeInt16`
145
145
  */
146
- readonly div: (x: import("ts-type-forge").WithSmallInt<TtfImported_NonNegativeInt16>, y: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | import("ts-type-forge").NormalizeBrandUnion<number & {
146
+ readonly div: (x: import("ts-type-forge").WithSmallInt<TtfImported_NonNegativeInt16>, y: import("ts-type-forge").RelaxedExclude<-40 | -39 | -38 | -37 | -36 | -35 | -34 | -33 | -32 | -31 | -30 | -29 | -28 | -27 | -26 | -25 | -24 | -23 | -22 | -21 | -20 | -19 | -18 | -17 | -16 | -15 | -14 | -13 | -12 | -11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39, -40 | -39 | -38 | -37 | -36 | -35 | -34 | -33 | -32 | -31 | -30 | -29 | -28 | -27 | -26 | -25 | -24 | -23 | -22 | -21 | -20 | -19 | -18 | -17 | -16 | -15 | -14 | -13 | -12 | -11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 0> | import("ts-type-forge").NormalizeBrandUnion<number & {
147
147
  readonly "!=0": true;
148
148
  readonly "< 2^15": true;
149
149
  readonly "< 2^16": true;
@@ -141,7 +141,7 @@ export declare const NonNegativeInt32: {
141
141
  * @param b - The divisor (must be non-zero)
142
142
  * @returns The floored quotient as a `NonNegativeInt32`
143
143
  */
144
- readonly div: (x: import("ts-type-forge").WithSmallInt<TtfImported_NonNegativeInt32>, y: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | import("ts-type-forge").NormalizeBrandUnion<number & {
144
+ readonly div: (x: import("ts-type-forge").WithSmallInt<TtfImported_NonNegativeInt32>, y: import("ts-type-forge").RelaxedExclude<-40 | -39 | -38 | -37 | -36 | -35 | -34 | -33 | -32 | -31 | -30 | -29 | -28 | -27 | -26 | -25 | -24 | -23 | -22 | -21 | -20 | -19 | -18 | -17 | -16 | -15 | -14 | -13 | -12 | -11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39, -40 | -39 | -38 | -37 | -36 | -35 | -34 | -33 | -32 | -31 | -30 | -29 | -28 | -27 | -26 | -25 | -24 | -23 | -22 | -21 | -20 | -19 | -18 | -17 | -16 | -15 | -14 | -13 | -12 | -11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 0> | import("ts-type-forge").NormalizeBrandUnion<number & {
145
145
  readonly "!=0": true;
146
146
  readonly "< 2^31": true;
147
147
  readonly "< 2^32": true;
@@ -13,7 +13,7 @@ const {
13
13
  random,
14
14
  sub
15
15
  } = TsDataForgeInternals.RefinedNumberUtils.operatorsForFloat({
16
- MIN_VALUE: Number.MAX_VALUE * -1,
16
+ MIN_VALUE: -Number.MAX_VALUE,
17
17
  MAX_VALUE: 0,
18
18
  typeNameInMessage
19
19
  });
@@ -1 +1 @@
1
- {"version":3,"file":"non-positive-finite-number.mjs","sources":["../../../src/number/branded-types/non-positive-finite-number.mts"],"sourcesContent":["import { type NonPositiveFiniteNumber as TtfImported_NonPositiveFiniteNumber } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type NonPositiveFiniteNumber = TtfImported_NonPositiveFiniteNumber;\n\ntype ElementType = NonPositiveFiniteNumber;\n\nconst typeNameInMessage = 'a non-positive finite number';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n fromNumber,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForFloat<\n ElementType,\n number,\n 0\n>({\n MIN_VALUE: Number.MAX_VALUE * -1,\n MAX_VALUE: 0,\n typeNameInMessage,\n} as const);\n\nconst floor = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.floor(\n x,\n ) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\nconst ceil = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.ceil(x) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\nconst round = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.round(\n x,\n ) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\n/**\n * Type guard that checks if a value is a non-positive finite number.\n *\n * Returns `true` only for a finite value — never `NaN`, `Infinity`, or\n * `-Infinity`.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-positive finite number, `false` otherwise\n */\nexport const isNonPositiveFiniteNumber = is;\n\n/**\n * Casts a `number` to the `NonPositiveFiniteNumber` branded type.\n *\n * Validates that the value is a non-positive finite number and returns it with\n * the `NonPositiveFiniteNumber` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NonPositiveFiniteNumber`\n * @throws {TypeError} If the value is not a non-positive finite number\n */\nexport const asNonPositiveFiniteNumber = castType;\n\n/**\n * Namespace providing type-safe operations for the `NonPositiveFiniteNumber`\n * branded type.\n *\n * The `NonPositiveFiniteNumber` type represents a non-positive finite number.\n */\nexport const NonPositiveFiniteNumber = {\n /**\n * Type guard that checks if a value is a non-positive finite number.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-positive finite number, `false` otherwise\n * @see {@link isNonPositiveFiniteNumber} for usage examples\n */\n is,\n\n /**\n * The largest value representable as `NonPositiveFiniteNumber` (the upper\n * saturation target of `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the smallest of the given non-positive finite numbers.\n *\n * @param values - The non-positive finite numbers to compare (at least one required)\n * @returns The smallest value as a `NonPositiveFiniteNumber`\n */\n min: min_,\n\n /**\n * Returns the largest of the given non-positive finite numbers.\n *\n * @param values - The non-positive finite numbers to compare (at least one required)\n * @returns The largest value as a `NonPositiveFiniteNumber`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into a `NonPositiveFiniteNumber`, saturating\n * it into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asNonPositiveFiniteNumber`, this is total: out-of-range inputs are\n * clamped to the nearest representable `NonPositiveFiniteNumber` instead of\n * throwing.\n *\n * @param value - The value to convert\n * @returns The value as a `NonPositiveFiniteNumber`\n */\n fromNumber,\n\n /**\n * Returns the greatest integer less than or equal to a non-positive finite\n * number.\n *\n * @param a - The non-positive finite number value\n * @returns The floored value as an integer\n */\n floor,\n\n /**\n * Returns the smallest integer greater than or equal to a non-positive finite\n * number.\n *\n * @param a - The non-positive finite number value\n * @returns The ceiled value as an integer\n */\n ceil,\n\n /**\n * Returns the value of a non-positive finite number rounded to the nearest\n * integer.\n *\n * @param a - The non-positive finite number value\n * @returns The rounded value as an integer\n */\n round,\n\n /**\n * Generates a random `NonPositiveFiniteNumber` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `NonPositiveFiniteNumber` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a\n * `NonPositiveFiniteNumber`.\n *\n * @param a - The base non-positive finite number\n * @param b - The exponent non-positive finite number\n * @returns `a ** b` as a `NonPositiveFiniteNumber`\n */\n pow,\n\n /**\n * Adds two non-positive finite numbers, returning `a + b` as a\n * `NonPositiveFiniteNumber`.\n *\n * @param a - The first non-positive finite number\n * @param b - The second non-positive finite number\n * @returns The sum of `a` and `b` as a `NonPositiveFiniteNumber`\n */\n add,\n\n /**\n * Subtracts two non-positive finite numbers, returning `a - b` as a\n * `NonPositiveFiniteNumber`.\n *\n * @param a - The first non-positive finite number\n * @param b - The second non-positive finite number\n * @returns The difference of `a` and `b` as a `NonPositiveFiniteNumber`\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;AAOA,MAAM,iBAAA,GAAoB,8BAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,iBAAA,CAI1C;AAAA,EACA,SAAA,EAAW,OAAO,SAAA,GAAY,EAAA;AAAA,EAC9B,SAAA,EAAW,CAAA;AAAA,EACX;AACF,CAAU,CAAA;AAEV,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAKA,IAAA,CAAK,KAAA;AAAA,IACH;AAAA;AACF,CAAA;AAIF,MAAM,OAAO,CACX,CAAA;AAAA;AAAA,EAKA,IAAA,CAAK,KAAK,CAAC;AAAA,CAAA;AAIb,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAKA,IAAA,CAAK,KAAA;AAAA,IACH;AAAA;AACF,CAAA;AAaK,MAAM,yBAAA,GAA4B;AAYlC,MAAM,yBAAA,GAA4B;AAQlC,MAAM,uBAAA,GAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQrC,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaL,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
1
+ {"version":3,"file":"non-positive-finite-number.mjs","sources":["../../../src/number/branded-types/non-positive-finite-number.mts"],"sourcesContent":["import { type NonPositiveFiniteNumber as TtfImported_NonPositiveFiniteNumber } from 'ts-type-forge';\nimport { TsDataForgeInternals } from '../refined-number-utils.mjs';\n\nexport type NonPositiveFiniteNumber = TtfImported_NonPositiveFiniteNumber;\n\ntype ElementType = NonPositiveFiniteNumber;\n\nconst typeNameInMessage = 'a non-positive finite number';\n\nconst {\n MAX_VALUE,\n add,\n castType,\n fromNumber,\n is,\n max: max_,\n min: min_,\n pow,\n random,\n sub,\n} = TsDataForgeInternals.RefinedNumberUtils.operatorsForFloat<\n ElementType,\n number,\n 0\n>({\n MIN_VALUE: -Number.MAX_VALUE,\n MAX_VALUE: 0,\n typeNameInMessage,\n} as const);\n\nconst floor = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.floor(\n x,\n ) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\nconst ceil = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.ceil(x) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\nconst round = (\n x: ElementType,\n): TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.round(\n x,\n ) as TsDataForgeInternals.RefinedNumberUtils.RemoveNonZeroBrandKey<\n TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>\n >;\n\n/**\n * Type guard that checks if a value is a non-positive finite number.\n *\n * Returns `true` only for a finite value — never `NaN`, `Infinity`, or\n * `-Infinity`.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-positive finite number, `false` otherwise\n */\nexport const isNonPositiveFiniteNumber = is;\n\n/**\n * Casts a `number` to the `NonPositiveFiniteNumber` branded type.\n *\n * Validates that the value is a non-positive finite number and returns it with\n * the `NonPositiveFiniteNumber` brand. Throws a `TypeError` otherwise.\n *\n * @param value - The value to cast\n * @returns The value as a `NonPositiveFiniteNumber`\n * @throws {TypeError} If the value is not a non-positive finite number\n */\nexport const asNonPositiveFiniteNumber = castType;\n\n/**\n * Namespace providing type-safe operations for the `NonPositiveFiniteNumber`\n * branded type.\n *\n * The `NonPositiveFiniteNumber` type represents a non-positive finite number.\n */\nexport const NonPositiveFiniteNumber = {\n /**\n * Type guard that checks if a value is a non-positive finite number.\n *\n * @param value - The value to check\n * @returns `true` if the value is a non-positive finite number, `false` otherwise\n * @see {@link isNonPositiveFiniteNumber} for usage examples\n */\n is,\n\n /**\n * The largest value representable as `NonPositiveFiniteNumber` (the upper\n * saturation target of `fromNumber`).\n */\n MAX_VALUE,\n\n /**\n * Returns the smallest of the given non-positive finite numbers.\n *\n * @param values - The non-positive finite numbers to compare (at least one required)\n * @returns The smallest value as a `NonPositiveFiniteNumber`\n */\n min: min_,\n\n /**\n * Returns the largest of the given non-positive finite numbers.\n *\n * @param values - The non-positive finite numbers to compare (at least one required)\n * @returns The largest value as a `NonPositiveFiniteNumber`\n */\n max: max_,\n\n /**\n * Converts an arbitrary `number` into a `NonPositiveFiniteNumber`, saturating\n * it into the range `[MIN_VALUE, MAX_VALUE]`.\n *\n * Unlike `asNonPositiveFiniteNumber`, this is total: out-of-range inputs are\n * clamped to the nearest representable `NonPositiveFiniteNumber` instead of\n * throwing.\n *\n * @param value - The value to convert\n * @returns The value as a `NonPositiveFiniteNumber`\n */\n fromNumber,\n\n /**\n * Returns the greatest integer less than or equal to a non-positive finite\n * number.\n *\n * @param a - The non-positive finite number value\n * @returns The floored value as an integer\n */\n floor,\n\n /**\n * Returns the smallest integer greater than or equal to a non-positive finite\n * number.\n *\n * @param a - The non-positive finite number value\n * @returns The ceiled value as an integer\n */\n ceil,\n\n /**\n * Returns the value of a non-positive finite number rounded to the nearest\n * integer.\n *\n * @param a - The non-positive finite number value\n * @returns The rounded value as an integer\n */\n round,\n\n /**\n * Generates a random `NonPositiveFiniteNumber` within the given range.\n *\n * The range is inclusive on both ends.\n *\n * @param min - The minimum value (inclusive)\n * @param max - The maximum value (inclusive)\n * @returns A random `NonPositiveFiniteNumber` in `[min, max]`\n */\n random,\n\n /**\n * Raises `a` to the power `b`, returning `a ** b` as a\n * `NonPositiveFiniteNumber`.\n *\n * @param a - The base non-positive finite number\n * @param b - The exponent non-positive finite number\n * @returns `a ** b` as a `NonPositiveFiniteNumber`\n */\n pow,\n\n /**\n * Adds two non-positive finite numbers, returning `a + b` as a\n * `NonPositiveFiniteNumber`.\n *\n * @param a - The first non-positive finite number\n * @param b - The second non-positive finite number\n * @returns The sum of `a` and `b` as a `NonPositiveFiniteNumber`\n */\n add,\n\n /**\n * Subtracts two non-positive finite numbers, returning `a - b` as a\n * `NonPositiveFiniteNumber`.\n *\n * @param a - The first non-positive finite number\n * @param b - The second non-positive finite number\n * @returns The difference of `a` and `b` as a `NonPositiveFiniteNumber`\n */\n sub,\n} as const;\n"],"names":[],"mappings":";;AAOA,MAAM,iBAAA,GAAoB,8BAAA;AAE1B,MAAM;AAAA,EACJ,SAAA;AAAA,EACA,GAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,EAAA;AAAA,EACA,GAAA,EAAK,IAAA;AAAA,EACL,GAAA,EAAK,IAAA;AAAA,EACL,GAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAA,GAAI,oBAAA,CAAqB,mBAAmB,iBAAA,CAI1C;AAAA,EACA,SAAA,EAAW,CAAC,MAAA,CAAO,SAAA;AAAA,EACnB,SAAA,EAAW,CAAA;AAAA,EACX;AACF,CAAU,CAAA;AAEV,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAKA,IAAA,CAAK,KAAA;AAAA,IACH;AAAA;AACF,CAAA;AAIF,MAAM,OAAO,CACX,CAAA;AAAA;AAAA,EAKA,IAAA,CAAK,KAAK,CAAC;AAAA,CAAA;AAIb,MAAM,QAAQ,CACZ,CAAA;AAAA;AAAA,EAKA,IAAA,CAAK,KAAA;AAAA,IACH;AAAA;AACF,CAAA;AAaK,MAAM,yBAAA,GAA4B;AAYlC,MAAM,yBAAA,GAA4B;AAQlC,MAAM,uBAAA,GAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQrC,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,GAAA,EAAK,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaL,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AACF;;;;"}
@@ -263,7 +263,7 @@ export declare const PositiveInt: {
263
263
  * @param b - The divisor (must be non-zero)
264
264
  * @returns The floored quotient as a `PositiveInt`
265
265
  */
266
- readonly div: (x: import("ts-type-forge").WithSmallInt<TtfImported_PositiveInt>, y: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | import("ts-type-forge").NormalizeBrandUnion<number & {
266
+ readonly div: (x: import("ts-type-forge").WithSmallInt<TtfImported_PositiveInt>, y: import("ts-type-forge").RelaxedExclude<-40 | -39 | -38 | -37 | -36 | -35 | -34 | -33 | -32 | -31 | -30 | -29 | -28 | -27 | -26 | -25 | -24 | -23 | -22 | -21 | -20 | -19 | -18 | -17 | -16 | -15 | -14 | -13 | -12 | -11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39, -40 | -39 | -38 | -37 | -36 | -35 | -34 | -33 | -32 | -31 | -30 | -29 | -28 | -27 | -26 | -25 | -24 | -23 | -22 | -21 | -20 | -19 | -18 | -17 | -16 | -15 | -14 | -13 | -12 | -11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 0> | import("ts-type-forge").NormalizeBrandUnion<number & {
267
267
  readonly "!=0": true;
268
268
  readonly "<=0": false;
269
269
  readonly "> -2^16": true;
@@ -142,7 +142,7 @@ export declare const PositiveInt16: {
142
142
  * @param b - The divisor (must be non-zero)
143
143
  * @returns The floored quotient as a `PositiveInt16`
144
144
  */
145
- readonly div: (x: import("ts-type-forge").WithSmallInt<TtfImported_PositiveInt16>, y: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | import("ts-type-forge").NormalizeBrandUnion<number & {
145
+ readonly div: (x: import("ts-type-forge").WithSmallInt<TtfImported_PositiveInt16>, y: import("ts-type-forge").RelaxedExclude<-40 | -39 | -38 | -37 | -36 | -35 | -34 | -33 | -32 | -31 | -30 | -29 | -28 | -27 | -26 | -25 | -24 | -23 | -22 | -21 | -20 | -19 | -18 | -17 | -16 | -15 | -14 | -13 | -12 | -11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39, -40 | -39 | -38 | -37 | -36 | -35 | -34 | -33 | -32 | -31 | -30 | -29 | -28 | -27 | -26 | -25 | -24 | -23 | -22 | -21 | -20 | -19 | -18 | -17 | -16 | -15 | -14 | -13 | -12 | -11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 0> | import("ts-type-forge").NormalizeBrandUnion<number & {
146
146
  readonly "!=0": true;
147
147
  readonly "< 2^15": true;
148
148
  readonly "< 2^16": true;