ts-data-forge 14.0.0 → 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.
- package/README.md +8 -7
- package/dist/array/impl/array-utils-modification.d.mts +18 -5
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts +12 -4
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +4 -5
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts +8 -3
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/collections/imap-mapped.mjs +1 -1
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.d.mts +1 -1
- package/dist/collections/imap.mjs +1 -1
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +2 -2
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.d.mts +2 -2
- package/dist/collections/iset.d.mts.map +1 -1
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/functional/match.d.mts.map +1 -1
- package/dist/functional/match.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +1 -1
- package/dist/number/branded-types/int16.d.mts +1 -1
- package/dist/number/branded-types/int32.d.mts +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +1 -1
- package/dist/number/branded-types/non-positive-finite-number.mjs +1 -1
- package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +1 -1
- package/dist/number/branded-types/safe-int.d.mts +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +1 -1
- package/dist/number/branded-types/uint.d.mts +1 -1
- package/dist/number/branded-types/uint16.d.mts +1 -1
- package/dist/number/branded-types/uint32.d.mts +1 -1
- package/dist/number/enum/int8.d.mts +2 -2
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.d.mts +2 -2
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/dist/number/num-arithmetic-types.d.mts +9 -10
- package/dist/number/num-arithmetic-types.d.mts.map +1 -1
- package/dist/number/refined-number-utils.d.mts +2 -2
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/object.d.mts +12 -12
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +5 -1
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/fast-deep-equal.d.mts.map +1 -1
- package/dist/others/fast-deep-equal.mjs +2 -2
- package/dist/others/fast-deep-equal.mjs.map +1 -1
- package/package.json +4 -5
- package/src/array/impl/array-utils-creation.test.mts +10 -8
- package/src/array/impl/array-utils-length-constraint-preservation.test.mts +2 -2
- package/src/array/impl/array-utils-modification.mts +41 -33
- package/src/array/impl/array-utils-modification.test.mts +77 -4
- package/src/array/impl/array-utils-shape-invariants.test.mts +526 -0
- package/src/array/impl/array-utils-slice-clamped.mts +2 -1
- package/src/array/impl/array-utils-slicing.test.mts +11 -3
- package/src/array/impl/array-utils-transformation.mts +70 -20
- package/src/array/impl/array-utils-transformation.test.mts +44 -10
- package/src/array/impl/array-utils-validation.mts +54 -10
- package/src/array/impl/array-utils-validation.test.mts +153 -3
- package/src/collections/imap-mapped.mts +1 -1
- package/src/collections/imap-mapped.test.mts +2 -2
- package/src/collections/imap.mts +2 -2
- package/src/collections/iset-mapped.mts +7 -3
- package/src/collections/iset-mapped.test.mts +1 -1
- package/src/collections/iset.mts +7 -3
- package/src/collections/iset.test.mts +9 -6
- package/src/functional/match.mts +5 -4
- package/src/functional/result.test.mts +5 -2
- package/src/guard/is-primitive.test.mts +1 -1
- package/src/guard/is-record.test.mts +4 -4
- package/src/guard/is-type.test.mts +2 -2
- package/src/number/branded-types/finite-number.test.mts +2 -2
- package/src/number/branded-types/non-negative-finite-number.test.mts +2 -2
- package/src/number/branded-types/non-positive-finite-number.mts +1 -1
- package/src/number/branded-types/non-positive-finite-number.test.mts +5 -9
- package/src/number/branded-types/non-zero-finite-number.test.mts +2 -2
- package/src/number/branded-types/positive-finite-number.test.mts +2 -2
- package/src/number/enum/int8.mts +2 -1
- package/src/number/enum/uint8.mts +6 -2
- package/src/number/num-arithmetic-types.mts +129 -24
- package/src/number/num.test.mts +11 -11
- package/src/number/refined-number-utils.mts +2 -1
- package/src/object/object.mts +29 -17
- package/src/object/object.test.mts +2 -1
- package/src/others/fast-deep-equal.mts +6 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils-validation.mjs","sources":["../../../src/array/impl/array-utils-validation.mts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"array-utils-validation.mjs","sources":["../../../src/array/impl/array-utils-validation.mts"],"sourcesContent":["import {\n type BoolOr,\n type ChangeArrayElement,\n type IsAny,\n type IsUnknown,\n type UnknownBrand,\n} from 'ts-type-forge';\nimport { asUint32, Num } from '../../number/index.mjs';\nimport { type ArrayIndex, type SizeType } from '../../types.mjs';\n\n/**\n * Type guard that checks if a value is an array.\n *\n * @example\n *\n * ```ts\n * const maybeArray: unknown = [1, 2, 3] as const;\n *\n * const maybeValue: unknown = 'Ada';\n *\n * assert.isTrue(Arr.isArray(maybeArray));\n *\n * assert.isFalse(Arr.isArray(maybeValue));\n *\n * if (Arr.isArray(maybeArray)) {\n * assert.deepStrictEqual(maybeArray, [1, 2, 3]);\n * }\n * ```\n */\nexport const isArray = <E,>(value: E): value is FilterArray<E> =>\n Array.isArray(value);\n\ntype FilterArray<T> = T extends T\n ? BoolOr<IsUnknown<T>, IsAny<T>> extends true\n ? Cast<readonly unknown[], T>\n : T extends readonly unknown[]\n ? T\n : never // Exclude non-array types\n : never;\n\ntype Cast<A, B> = A extends B ? A : never;\n\n// validation\n\n/**\n * Tests whether all elements in an array pass a test implemented by a predicate.\n *\n * @example\n *\n * ```ts\n * const numbers = [2, 4, 6] as const;\n *\n * const words = ['Ada', 'Grace'] as const;\n *\n * const allEven = Arr.every(numbers, (value) => value % 2 === 0);\n *\n * const allStartWithA = Arr.every(words, (value) => value.startsWith('A'));\n *\n * assert.isTrue(allEven);\n *\n * assert.isFalse(allStartWithA);\n * ```\n */\n// Type guard overloads - narrow the entire array type.\n//\n// Both narrowed types are intersected with `Ar`: a type predicate's type has\n// to be assignable to the parameter's type, and neither the deferred\n// conditional `ChangeArrayElement<Ar, S>` nor the mapped type over a generic\n// `Ar` is (TS2677). The intersection also keeps whatever the caller already\n// knew about the array — a branded five-tuple stays a five-tuple.\nexport function every<\n const Ar extends readonly unknown[] & UnknownBrand,\n S extends Ar[number],\n>(\n array: Ar,\n predicate: (a: Ar[number], index: ArrayIndex<Ar>) => a is S,\n): array is ChangeArrayElement<Ar, S> & Ar;\n\n// A plain array or tuple carries no length brand, so the homomorphic mapping\n// is the whole answer — same reasoning as in `map`.\nexport function every<\n const Ar extends readonly unknown[],\n S extends Ar[number],\n>(\n array: Ar,\n predicate: (a: Ar[number], index: ArrayIndex<Ar>) => a is S,\n): array is Readonly<{ [K in keyof Ar]: S }> & Ar;\n\n// Regular boolean predicate overloads\nexport function every<const Ar extends readonly unknown[]>(\n array: Ar,\n predicate: (a: Ar[number], index: ArrayIndex<Ar>) => boolean,\n): boolean;\n\n// curried version\n//\n// As in `map`, the branded and the plain case have to be overloads *of the\n// returned function*, not two overloads of `every` itself: both curried\n// signatures take the same single predicate, so overload resolution would\n// always pick the first and the second would be dead — which is what left a\n// plain `readonly unknown[]` unable to satisfy the `UnknownBrand` constraint\n// at the call site of the returned guard.\n//\n// The intersection is also what keeps the group compatible with the\n// implementation signature. A lone `<Ar extends readonly E[] & UnknownBrand>`\n// signature is not something `(array: readonly E[]) => boolean` can implement\n// (TS2394); the unbranded member of the intersection is, and one matching\n// member is enough.\nexport function every<E, S extends E>(\n predicate: (a: E, index: SizeType.Arr) => a is S,\n): (<const Ar extends readonly E[] & UnknownBrand>(\n array: Ar,\n) => array is ChangeArrayElement<Ar, S> & Ar) &\n (<const Ar extends readonly E[]>(\n array: Ar,\n ) => array is Readonly<{ [K in keyof Ar]: S }> & Ar);\n\nexport function every<E>(\n predicate: (a: E, index: SizeType.Arr) => boolean,\n): (array: readonly E[]) => boolean;\n\nexport function every<E>(\n ...args:\n | readonly [\n array: readonly E[],\n predicate: (a: E, index: SizeType.Arr) => boolean,\n ]\n | readonly [predicate: (a: E, index: SizeType.Arr) => boolean]\n): boolean | ((array: readonly E[]) => boolean) {\n switch (args.length) {\n case 2:\n return everyImpl(...args);\n\n case 1:\n return (array) => everyImpl(array, ...args);\n }\n}\n\nconst everyImpl = <E,>(\n array: readonly E[],\n predicate: (a: E, index: SizeType.Arr) => boolean,\n): boolean => array.every((a, i) => predicate(a, asUint32(i)));\n\n/**\n * Tests whether at least one element in an array passes a test implemented by a predicate.\n *\n * @example\n *\n * ```ts\n * const numbers = [1, 3, 5] as const;\n *\n * const words = ['Ada', 'Grace'] as const;\n *\n * const hasEven = Arr.some(numbers, (value) => value % 2 === 0);\n *\n * const hasShortName = Arr.some(words, (value) => value.length <= 3);\n *\n * assert.isFalse(hasEven);\n *\n * assert.isTrue(hasShortName);\n * ```\n */\nexport function some<const Ar extends readonly unknown[]>(\n array: Ar,\n predicate: (a: Ar[number], index: ArrayIndex<Ar>) => boolean,\n): boolean;\n\nexport function some<E>(\n predicate: (a: E, index: SizeType.Arr) => boolean,\n): (array: readonly E[]) => boolean;\n\nexport function some<E>(\n ...args:\n | readonly [\n array: readonly E[],\n predicate: (a: E, index: SizeType.Arr) => boolean,\n ]\n | readonly [predicate: (a: E, index: SizeType.Arr) => boolean]\n): boolean | ((array: readonly E[]) => boolean) {\n switch (args.length) {\n case 2:\n return someImpl(...args);\n\n case 1:\n return (array) => someImpl(array, ...args);\n }\n}\n\nconst someImpl = <E,>(\n array: readonly E[],\n predicate: (a: E, index: SizeType.Arr) => boolean,\n): boolean => array.some((a, i) => predicate(a, asUint32(i)));\n\n/**\n * Checks if an index is within the valid range of an array.\n *\n * @example\n *\n * ```ts\n * const items = ['Ada', 'Grace', 'Katherine'] as const;\n *\n * assert.isTrue(Arr.indexIsInRange(items, 1));\n *\n * assert.isFalse(Arr.indexIsInRange(items, 3));\n *\n * if (Arr.indexIsInRange(items, 2)) {\n * assert.isTrue(items[2] === 'Katherine');\n * }\n * ```\n */\nexport const indexIsInRange = <E,>(\n array: readonly E[],\n index: SizeType.ArgArr,\n): boolean => Num.isInRange(0, array.length)(index);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BO,MAAM,OAAA,GAAU,CAAK,KAAA,KAC1B,KAAA,CAAM,QAAQ,KAAK;AA2Fd,SAAS,SACX,IAAA,EAM2C;AAC9C,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA;AACH,MAAA,OAAO,SAAA,CAAU,GAAG,IAAI,CAAA;AAAA,IAE1B,KAAK,CAAA;AACH,MAAA,OAAO,CAAC,KAAA,KAAU,SAAA,CAAU,KAAA,EAAO,GAAG,IAAI,CAAA;AAAA;AAEhD;AAEA,MAAM,SAAA,GAAY,CAChB,KAAA,EACA,SAAA,KACY,MAAM,KAAA,CAAM,CAAC,CAAA,EAAG,CAAA,KAAM,SAAA,CAAU,CAAA,EAAG,QAAA,CAAS,CAAC,CAAC,CAAC,CAAA;AA8BtD,SAAS,QACX,IAAA,EAM2C;AAC9C,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA;AACH,MAAA,OAAO,QAAA,CAAS,GAAG,IAAI,CAAA;AAAA,IAEzB,KAAK,CAAA;AACH,MAAA,OAAO,CAAC,KAAA,KAAU,QAAA,CAAS,KAAA,EAAO,GAAG,IAAI,CAAA;AAAA;AAE/C;AAEA,MAAM,QAAA,GAAW,CACf,KAAA,EACA,SAAA,KACY,MAAM,IAAA,CAAK,CAAC,CAAA,EAAG,CAAA,KAAM,SAAA,CAAU,CAAA,EAAG,QAAA,CAAS,CAAC,CAAC,CAAC,CAAA;AAmBrD,MAAM,cAAA,GAAiB,CAC5B,KAAA,EACA,KAAA,KACY,GAAA,CAAI,UAAU,CAAA,EAAG,KAAA,CAAM,MAAM,CAAA,CAAE,KAAK;;;;"}
|
|
@@ -178,7 +178,7 @@ class IMapMappedClass {
|
|
|
178
178
|
break;
|
|
179
179
|
case "update": {
|
|
180
180
|
const curr = mut_result.get(key);
|
|
181
|
-
if (
|
|
181
|
+
if (curr === void 0 || !mut_result.has(key)) {
|
|
182
182
|
if (this.#showNotFoundMessage) {
|
|
183
183
|
console.warn(
|
|
184
184
|
`IMapMapped.withMutations::update: key not found: ${String(key)}`
|
|
@@ -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,IAA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9B,MAAA,MAAM,CAAA;AAAA,IACR;AAAA,EACF;AAAA;AAAA,EAGA,CAAC,IAAA,GAA4B;AAC3B,IAAA,KAAA,MAAW,EAAA,IAAM,IAAA,CAAK,IAAA,CAAK,IAAA,EAAK,EAAG;AACjC,MAAA,MAAM,IAAA,CAAK,SAAS,EAAE,CAAA;AAAA,IACxB;AAAA,EACF;AAAA;AAAA,EAGA,MAAA,GAA8B;AAC5B,IAAA,OAAO,IAAA,CAAK,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;;;;"}
|
|
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,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,EAzHa,UAAA,KAAA,UAAA,GAAA,EAAA,CAAA,CAAA;AAmJjB,MAAM,eAAA,CAEN;AAAA,EACW,IAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,oBAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeT,WAAA,CACE,QAAA,EACA,KAAA,EACA,OAAA,EACA,sBAA+B,KAAA,EAC/B;AACA,IAAA,IAAA,CAAK,OAAO,IAAI,GAAA,CAAI,KAAA,CAAM,IAAA,CAAK,UAAU,CAAC,CAAC,CAAA,EAAG,CAAC,MAAM,CAAC,KAAA,CAAM,CAAC,CAAA,EAAG,CAAC,CAAC,CAAC,CAAA;AAEnE,IAAA,IAAA,CAAK,MAAA,GAAS,KAAA;AAEd,I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AGA,QAAA,GAA+B;AAC7B,IAAA,OAAO,IAAA,CAAK,IAAA;AAAA,EACd;AACF;;;;"}
|
|
@@ -512,7 +512,7 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
512
512
|
* const entries = [
|
|
513
513
|
* ['k1', 'v1'],
|
|
514
514
|
* ['k2', 'v2'],
|
|
515
|
-
* ] as const satisfies readonly
|
|
515
|
+
* ] as const satisfies readonly FixedLengthTuple<2, string>[];
|
|
516
516
|
*
|
|
517
517
|
* const map = IMap.create(entries);
|
|
518
518
|
*
|
|
@@ -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 (
|
|
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 (readonly [string, 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,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;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"}
|
|
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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IAAA,CAAK,KAAK,OAAA,EAAQ;AAAA,EAC3B;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,GAA8B;AAC5B,IAAA,OAAO,IAAA,CAAK,IAAA;AAAA,EACd;AACF;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ReadonlyRecord, type WidenLiteral } from 'ts-type-forge';
|
|
1
|
+
import { type FixedLengthTuple, type ReadonlyRecord, type WidenLiteral } from 'ts-type-forge';
|
|
2
2
|
import { type MapSetKeyType, type SizeType } from '../types.mjs';
|
|
3
3
|
/**
|
|
4
4
|
* Interface for an immutable set with custom element mapping and membership
|
|
@@ -750,7 +750,7 @@ type ISetMappedInterface<K, KM extends MapSetKeyType> = Readonly<{
|
|
|
750
750
|
*
|
|
751
751
|
* @returns An iterable iterator of entries.
|
|
752
752
|
*/
|
|
753
|
-
entries: () => IterableIterator<
|
|
753
|
+
entries: () => IterableIterator<FixedLengthTuple<2, K>>;
|
|
754
754
|
/**
|
|
755
755
|
* Converts the elements of the set to an array.
|
|
756
756
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iset-mapped.d.mts","sourceRoot":"","sources":["../../src/collections/iset-mapped.mts"],"names":[],"mappings":"AACA,OAAO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