ts-data-forge 3.2.0 → 3.3.1
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 +45 -21
- package/dist/array/impl/array-utils-creation.d.mts +116 -0
- package/dist/array/impl/array-utils-creation.d.mts.map +1 -0
- package/dist/array/impl/array-utils-creation.mjs +110 -0
- package/dist/array/impl/array-utils-creation.mjs.map +1 -0
- package/dist/array/impl/array-utils-element-access.d.mts +61 -0
- package/dist/array/impl/array-utils-element-access.d.mts.map +1 -0
- package/dist/array/impl/array-utils-element-access.mjs +66 -0
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -0
- package/dist/array/impl/array-utils-iterators.d.mts +59 -0
- package/dist/array/impl/array-utils-iterators.d.mts.map +1 -0
- package/dist/array/impl/array-utils-iterators.mjs +104 -0
- package/dist/array/impl/array-utils-iterators.mjs.map +1 -0
- package/dist/array/impl/array-utils-modification.d.mts +154 -0
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -0
- package/dist/array/impl/array-utils-modification.mjs +139 -0
- package/dist/array/impl/array-utils-modification.mjs.map +1 -0
- package/dist/array/impl/array-utils-reducing-value.d.mts +214 -0
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -0
- package/dist/array/impl/array-utils-reducing-value.mjs +160 -0
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -0
- package/dist/array/impl/array-utils-search.d.mts +179 -0
- package/dist/array/impl/array-utils-search.d.mts.map +1 -0
- package/dist/array/impl/array-utils-search.mjs +153 -0
- package/dist/array/impl/array-utils-search.mjs.map +1 -0
- package/dist/array/impl/array-utils-set-op.d.mts +100 -0
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -0
- package/dist/array/impl/array-utils-set-op.mjs +137 -0
- package/dist/array/impl/array-utils-set-op.mjs.map +1 -0
- package/dist/array/impl/array-utils-size.d.mts +24 -0
- package/dist/array/impl/array-utils-size.d.mts.map +1 -0
- package/dist/array/impl/array-utils-size.mjs +28 -0
- package/dist/array/impl/array-utils-size.mjs.map +1 -0
- package/dist/array/impl/array-utils-slice-clamped.d.mts +18 -0
- package/dist/array/impl/array-utils-slice-clamped.d.mts.map +1 -0
- package/dist/array/impl/array-utils-slice-clamped.mjs +49 -0
- package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -0
- package/dist/array/impl/array-utils-slicing.d.mts +120 -0
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -0
- package/dist/array/impl/array-utils-slicing.mjs +140 -0
- package/dist/array/impl/array-utils-slicing.mjs.map +1 -0
- package/dist/array/impl/array-utils-transformation.d.mts +348 -0
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -0
- package/dist/array/impl/array-utils-transformation.mjs +331 -0
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -0
- package/dist/array/impl/array-utils-validation.d.mts +149 -0
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -0
- package/dist/array/impl/array-utils-validation.mjs +166 -0
- package/dist/array/impl/array-utils-validation.mjs.map +1 -0
- package/dist/array/impl/index.d.mts +13 -0
- package/dist/array/impl/index.d.mts.map +1 -0
- package/dist/array/impl/index.mjs +13 -0
- package/dist/array/impl/index.mjs.map +1 -0
- package/dist/array/index.d.mts +1 -1
- package/dist/array/index.d.mts.map +1 -1
- package/dist/array/index.mjs +2 -1
- package/dist/array/index.mjs.map +1 -1
- package/dist/collections/imap-mapped.d.mts +83 -253
- package/dist/collections/imap-mapped.d.mts.map +1 -1
- package/dist/collections/imap-mapped.mjs +33 -164
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.d.mts +436 -163
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +74 -94
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +828 -345
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs +200 -242
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.d.mts +397 -205
- package/dist/collections/iset.d.mts.map +1 -1
- package/dist/collections/iset.mjs +102 -184
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.d.mts +155 -135
- package/dist/collections/queue.d.mts.map +1 -1
- package/dist/collections/queue.mjs +55 -156
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.d.mts +154 -154
- package/dist/collections/stack.d.mts.map +1 -1
- package/dist/collections/stack.mjs +54 -203
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/entry-point.d.mts +3 -0
- package/dist/entry-point.d.mts.map +1 -0
- package/dist/entry-point.mjs +62 -0
- package/dist/entry-point.mjs.map +1 -0
- package/dist/expect-type.d.mts +43 -172
- package/dist/expect-type.d.mts.map +1 -1
- package/dist/expect-type.mjs +43 -172
- package/dist/expect-type.mjs.map +1 -1
- package/dist/functional/match.d.mts +35 -140
- package/dist/functional/match.d.mts.map +1 -1
- package/dist/functional/match.mjs.map +1 -1
- package/dist/functional/optional.d.mts +282 -160
- package/dist/functional/optional.d.mts.map +1 -1
- package/dist/functional/optional.mjs +131 -71
- package/dist/functional/optional.mjs.map +1 -1
- package/dist/functional/pipe.d.mts +59 -113
- package/dist/functional/pipe.d.mts.map +1 -1
- package/dist/functional/pipe.mjs.map +1 -1
- package/dist/functional/result.d.mts +433 -332
- package/dist/functional/result.d.mts.map +1 -1
- package/dist/functional/result.mjs +233 -239
- package/dist/functional/result.mjs.map +1 -1
- package/dist/globals.d.mts +12 -5
- package/dist/guard/has-key.d.mts +23 -74
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +23 -74
- package/dist/guard/has-key.mjs.map +1 -1
- package/dist/guard/is-non-empty-string.d.mts +20 -87
- package/dist/guard/is-non-empty-string.d.mts.map +1 -1
- package/dist/guard/is-non-empty-string.mjs +20 -87
- package/dist/guard/is-non-empty-string.mjs.map +1 -1
- package/dist/guard/is-non-null-object.d.mts +14 -84
- package/dist/guard/is-non-null-object.d.mts.map +1 -1
- package/dist/guard/is-non-null-object.mjs +14 -84
- package/dist/guard/is-non-null-object.mjs.map +1 -1
- package/dist/guard/is-primitive.d.mts +13 -126
- package/dist/guard/is-primitive.d.mts.map +1 -1
- package/dist/guard/is-primitive.mjs +13 -126
- package/dist/guard/is-primitive.mjs.map +1 -1
- package/dist/guard/is-record.d.mts +21 -132
- package/dist/guard/is-record.d.mts.map +1 -1
- package/dist/guard/is-record.mjs +21 -132
- package/dist/guard/is-record.mjs.map +1 -1
- package/dist/guard/is-type.d.mts +201 -238
- package/dist/guard/is-type.d.mts.map +1 -1
- package/dist/guard/is-type.mjs +201 -238
- package/dist/guard/is-type.mjs.map +1 -1
- package/dist/guard/key-is-in.d.mts +22 -139
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +22 -139
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/dist/iterator/range.d.mts +29 -62
- package/dist/iterator/range.d.mts.map +1 -1
- package/dist/iterator/range.mjs.map +1 -1
- package/dist/json/json.d.mts +191 -121
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +238 -136
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/finite-number.d.mts +24 -156
- package/dist/number/branded-types/finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/finite-number.mjs +27 -159
- package/dist/number/branded-types/finite-number.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +122 -120
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int.mjs +122 -120
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/int16.d.mts +22 -30
- package/dist/number/branded-types/int16.d.mts.map +1 -1
- package/dist/number/branded-types/int16.mjs +22 -30
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.d.mts +22 -31
- package/dist/number/branded-types/int32.d.mts.map +1 -1
- package/dist/number/branded-types/int32.mjs +22 -31
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +28 -36
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs +31 -39
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +24 -34
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs +24 -34
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +26 -35
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs +26 -35
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts +22 -37
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.mjs +25 -40
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int.d.mts +15 -30
- package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int.mjs +15 -30
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts +27 -35
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs +27 -35
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +29 -36
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs +29 -36
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +37 -38
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +39 -40
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +24 -35
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs +24 -35
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +24 -35
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs +24 -35
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +26 -40
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs +29 -43
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +133 -123
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +133 -123
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +24 -35
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int16.mjs +24 -35
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +24 -35
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int32.mjs +24 -35
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +159 -33
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +160 -34
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +24 -35
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint16.mjs +24 -35
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +26 -36
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint32.mjs +26 -36
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +140 -99
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +142 -101
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +24 -33
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +25 -34
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.d.mts +121 -30
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +121 -30
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +26 -34
- package/dist/number/branded-types/uint16.d.mts.map +1 -1
- package/dist/number/branded-types/uint16.mjs +26 -34
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +26 -68
- package/dist/number/branded-types/uint32.d.mts.map +1 -1
- package/dist/number/branded-types/uint32.mjs +26 -68
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/int8.d.mts +37 -101
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/int8.mjs +39 -170
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.d.mts +45 -55
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/number/enum/uint8.mjs +46 -155
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/dist/number/num.d.mts +145 -206
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/num.mjs +143 -199
- package/dist/number/num.mjs.map +1 -1
- package/dist/number/refined-number-utils.d.mts +97 -21
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +91 -20
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/object.d.mts +126 -208
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +68 -102
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/cast-mutable.d.mts +12 -88
- package/dist/others/cast-mutable.d.mts.map +1 -1
- package/dist/others/cast-mutable.mjs +13 -89
- package/dist/others/cast-mutable.mjs.map +1 -1
- package/dist/others/cast-readonly.d.mts +12 -168
- package/dist/others/cast-readonly.d.mts.map +1 -1
- package/dist/others/cast-readonly.mjs +13 -169
- package/dist/others/cast-readonly.mjs.map +1 -1
- package/dist/others/if-then.d.mts +6 -83
- package/dist/others/if-then.d.mts.map +1 -1
- package/dist/others/if-then.mjs +6 -83
- package/dist/others/if-then.mjs.map +1 -1
- package/dist/others/map-nullable.d.mts +12 -136
- package/dist/others/map-nullable.d.mts.map +1 -1
- package/dist/others/map-nullable.mjs.map +1 -1
- package/dist/others/memoize-function.d.mts +14 -157
- package/dist/others/memoize-function.d.mts.map +1 -1
- package/dist/others/memoize-function.mjs +14 -157
- package/dist/others/memoize-function.mjs.map +1 -1
- package/dist/others/tuple.d.mts +33 -151
- package/dist/others/tuple.d.mts.map +1 -1
- package/dist/others/tuple.mjs +33 -151
- package/dist/others/tuple.mjs.map +1 -1
- package/dist/others/unknown-to-string.d.mts +11 -125
- package/dist/others/unknown-to-string.d.mts.map +1 -1
- package/dist/others/unknown-to-string.mjs +14 -127
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/dist/promise/promise.d.mts +33 -20
- package/dist/promise/promise.d.mts.map +1 -1
- package/dist/promise/promise.mjs +34 -21
- package/dist/promise/promise.mjs.map +1 -1
- package/dist/types.d.mts +1 -1
- package/package.json +54 -50
- package/src/array/impl/array-utils-creation.mts +192 -0
- package/src/array/{array-utils-creation.test.mts → impl/array-utils-creation.test.mts} +121 -72
- package/src/array/impl/array-utils-element-access.mts +115 -0
- package/src/array/impl/array-utils-element-access.test.mts +151 -0
- package/src/array/impl/array-utils-iterators.mts +79 -0
- package/src/array/impl/array-utils-iterators.test.mts +98 -0
- package/src/array/impl/array-utils-modification.mts +434 -0
- package/src/array/{array-utils-modification.test.mts → impl/array-utils-modification.test.mts} +41 -28
- package/src/array/{array-utils-overload-type-error.test.mts → impl/array-utils-overload-type-error.test.mts} +33 -33
- package/src/array/impl/array-utils-reducing-value.mts +551 -0
- package/src/array/{array-utils-reducing-value.test.mts → impl/array-utils-reducing-value.test.mts} +45 -50
- package/src/array/impl/array-utils-search.mts +509 -0
- package/src/array/impl/array-utils-search.test.mts +346 -0
- package/src/array/impl/array-utils-set-op.mts +166 -0
- package/src/array/{array-utils-set-op.test.mts → impl/array-utils-set-op.test.mts} +42 -35
- package/src/array/impl/array-utils-size.mts +30 -0
- package/src/array/impl/array-utils-size.test.mts +9 -0
- package/src/array/impl/array-utils-slice-clamped.mts +51 -0
- package/src/array/{array-utils-slice-clamped.test.mts → impl/array-utils-slice-clamped.test.mts} +12 -12
- package/src/array/impl/array-utils-slicing.mts +275 -0
- package/src/array/impl/array-utils-slicing.test.mts +158 -0
- package/src/array/impl/array-utils-transformation.mts +746 -0
- package/src/array/{array-utils-transformation.test.mts → impl/array-utils-transformation.test.mts} +662 -889
- package/src/array/impl/array-utils-validation.mts +241 -0
- package/src/array/{array-utils-validation.test.mts → impl/array-utils-validation.test.mts} +194 -107
- package/src/array/{array.test.mts → impl/array.test.mts} +2 -2
- package/src/array/impl/index.mts +12 -0
- package/src/array/index.mts +1 -1
- package/src/collections/imap-mapped.mts +99 -265
- package/src/collections/imap.mts +477 -174
- package/src/collections/imap.test.mts +12 -19
- package/src/collections/iset-mapped.mts +892 -358
- package/src/collections/iset.mts +429 -213
- package/src/collections/queue.mts +174 -200
- package/src/collections/stack.mts +172 -245
- package/src/collections/stack.test.mts +9 -1
- package/src/entry-point.mts +2 -0
- package/src/expect-type.mts +43 -172
- package/src/functional/match.mts +35 -145
- package/src/functional/optional.mts +285 -163
- package/src/functional/optional.test.mts +4 -1
- package/src/functional/pipe.mts +60 -113
- package/src/functional/result.mts +452 -351
- package/src/functional/result.test.mts +9 -2
- package/src/globals.d.mts +12 -5
- package/src/guard/has-key.mts +23 -74
- package/src/guard/is-non-empty-string.mts +20 -87
- package/src/guard/is-non-null-object.mts +14 -84
- package/src/guard/is-non-null-object.test.mts +1 -1
- package/src/guard/is-primitive.mts +13 -126
- package/src/guard/is-primitive.test.mts +1 -1
- package/src/guard/is-record.mts +21 -132
- package/src/guard/is-record.test.mts +0 -1
- package/src/guard/is-type.mts +201 -238
- package/src/guard/is-type.test.mts +7 -7
- package/src/guard/key-is-in.mts +22 -139
- package/src/index.mts +0 -1
- package/src/iterator/range.mts +29 -62
- package/src/json/json.mts +202 -134
- package/src/json/json.test.mts +1 -3
- package/src/number/branded-types/finite-number.mts +27 -159
- package/src/number/branded-types/int.mts +122 -120
- package/src/number/branded-types/int16.mts +22 -30
- package/src/number/branded-types/int16.test.mts +24 -24
- package/src/number/branded-types/int32.mts +22 -31
- package/src/number/branded-types/int32.test.mts +39 -39
- package/src/number/branded-types/non-negative-finite-number.mts +31 -39
- package/src/number/branded-types/non-negative-int16.mts +24 -34
- package/src/number/branded-types/non-negative-int16.test.mts +16 -16
- package/src/number/branded-types/non-negative-int32.mts +26 -35
- package/src/number/branded-types/non-negative-int32.test.mts +30 -30
- package/src/number/branded-types/non-zero-finite-number.mts +25 -40
- package/src/number/branded-types/non-zero-int.mts +15 -30
- package/src/number/branded-types/non-zero-int16.mts +27 -35
- package/src/number/branded-types/non-zero-int16.test.mts +26 -26
- package/src/number/branded-types/non-zero-int32.mts +29 -36
- package/src/number/branded-types/non-zero-int32.test.mts +45 -42
- package/src/number/branded-types/non-zero-safe-int.mts +39 -40
- package/src/number/branded-types/non-zero-uint16.mts +24 -35
- package/src/number/branded-types/non-zero-uint16.test.mts +16 -16
- package/src/number/branded-types/non-zero-uint32.mts +24 -35
- package/src/number/branded-types/non-zero-uint32.test.mts +28 -28
- package/src/number/branded-types/positive-finite-number.mts +29 -43
- package/src/number/branded-types/positive-int.mts +134 -124
- package/src/number/branded-types/positive-int16.mts +24 -35
- package/src/number/branded-types/positive-int16.test.mts +14 -14
- package/src/number/branded-types/positive-int32.mts +24 -35
- package/src/number/branded-types/positive-int32.test.mts +26 -26
- package/src/number/branded-types/positive-safe-int.mts +160 -34
- package/src/number/branded-types/positive-uint16.mts +24 -35
- package/src/number/branded-types/positive-uint16.test.mts +16 -16
- package/src/number/branded-types/positive-uint32.mts +26 -36
- package/src/number/branded-types/positive-uint32.test.mts +31 -28
- package/src/number/branded-types/safe-int.mts +142 -101
- package/src/number/branded-types/safe-uint.mts +25 -34
- package/src/number/branded-types/uint.mts +121 -30
- package/src/number/branded-types/uint16.mts +26 -34
- package/src/number/branded-types/uint16.test.mts +16 -16
- package/src/number/branded-types/uint32.mts +26 -68
- package/src/number/branded-types/uint32.test.mts +28 -28
- package/src/number/enum/int8.mts +39 -170
- package/src/number/enum/uint8.mts +46 -155
- package/src/number/num.mts +157 -212
- package/src/number/num.test.mts +4 -4
- package/src/number/refined-number-utils.mts +109 -26
- package/src/object/object.mts +130 -212
- package/src/object/object.test.mts +29 -0
- package/src/others/cast-mutable.mts +13 -89
- package/src/others/cast-mutable.test.mts +80 -0
- package/src/others/cast-readonly.mts +13 -169
- package/src/others/if-then.mts +6 -83
- package/src/others/map-nullable.mts +12 -136
- package/src/others/map-nullable.test.mts +6 -6
- package/src/others/memoize-function.mts +14 -157
- package/src/others/tuple.mts +33 -151
- package/src/others/unknown-to-string.mts +15 -127
- package/src/others/unknown-to-string.test.mts +14 -2
- package/src/promise/promise.mts +34 -21
- package/src/promise/promise.test.mts +43 -0
- package/dist/array/array-utils.d.mts +0 -2956
- package/dist/array/array-utils.d.mts.map +0 -1
- package/dist/array/array-utils.mjs +0 -1838
- package/dist/array/array-utils.mjs.map +0 -1
- package/src/array/array-utils-search.test.mts +0 -169
- package/src/array/array-utils-slicing.test.mts +0 -274
- package/src/array/array-utils.mts +0 -4834
package/src/collections/imap.mts
CHANGED
|
@@ -1,55 +1,70 @@
|
|
|
1
|
-
import { Optional } from '../functional/index.mjs';
|
|
1
|
+
import { Optional, pipe } from '../functional/index.mjs';
|
|
2
2
|
import { asUint32 } from '../number/index.mjs';
|
|
3
3
|
import { tp, unknownToString } from '../others/index.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Interface for an immutable map with
|
|
6
|
+
* Interface for an immutable map with lookup operations and functional
|
|
7
|
+
* programming patterns.
|
|
7
8
|
*
|
|
8
|
-
* This interface defines all methods and properties available on IMap
|
|
9
|
-
* that modify the map return new IMap instances,
|
|
10
|
-
*
|
|
9
|
+
* This interface defines all methods and properties available on IMap
|
|
10
|
+
* instances. All operations that modify the map return new IMap instances,
|
|
11
|
+
* preserving immutability. The underlying implementation uses JavaScript's
|
|
12
|
+
* native Map but creates copies on mutations to maintain immutability.
|
|
11
13
|
*
|
|
12
14
|
* **Immutability Guarantees:**
|
|
15
|
+
*
|
|
13
16
|
* - All mutation operations (set, delete, update) return new IMap instances
|
|
14
17
|
* - Original IMap instances are never modified
|
|
15
18
|
* - Safe for concurrent access and functional programming patterns
|
|
16
19
|
*
|
|
17
20
|
* **Performance Characteristics:**
|
|
18
|
-
*
|
|
19
|
-
* -
|
|
21
|
+
*
|
|
22
|
+
* - get/has: O(1) average case
|
|
23
|
+
* - set/delete: O(n) due to copying for immutability
|
|
20
24
|
* - map/filter operations: O(n)
|
|
21
|
-
* -
|
|
25
|
+
* - iteration: O(n)
|
|
22
26
|
*
|
|
23
|
-
* @template K The type of the keys in the map. Must extend MapSetKeyType
|
|
27
|
+
* @template K The type of the keys in the map. Must extend MapSetKeyType
|
|
28
|
+
* (string, number, boolean, etc.)
|
|
24
29
|
* @template V The type of the values in the map.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* // This is a type alias describing an interface, so it's not directly instantiated.
|
|
29
|
-
* // See IMap.create for examples of creating IMap instances that conform to this interface.
|
|
30
|
-
*
|
|
31
|
-
* // Example of how you might use a variable that implements this structure:
|
|
32
|
-
* declare const userMap: IMap<string, User>;
|
|
33
|
-
*
|
|
34
|
-
* // Immutable operations - original map is never modified
|
|
35
|
-
* const hasUser = userMap.has("alice"); // O(1)
|
|
36
|
-
* const user = userMap.get("alice").unwrapOr(defaultUser); // O(1)
|
|
37
|
-
* const newMap = userMap.set("bob", newUser); // O(1) - returns new IMap
|
|
38
|
-
* const updated = userMap.update("alice", u => ({ ...u, active: true })); // O(1)
|
|
39
|
-
*
|
|
40
|
-
* // Functional transformations
|
|
41
|
-
* const activeUsers = userMap.map((user, id) => ({ ...user, lastSeen: Date.now() })); // O(n)
|
|
42
|
-
* ```
|
|
43
30
|
*/
|
|
44
31
|
type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
45
32
|
// Getting information
|
|
46
33
|
|
|
47
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* The number of elements in the map.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* const entries = [
|
|
41
|
+
* ['a', 1],
|
|
42
|
+
* ['b', 2],
|
|
43
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
44
|
+
*
|
|
45
|
+
* const map = IMap.create(entries);
|
|
46
|
+
*
|
|
47
|
+
* assert(map.size === 2);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
48
50
|
size: SizeType.Arr;
|
|
49
51
|
|
|
50
52
|
/**
|
|
51
|
-
* Checks if a key exists in the map.
|
|
52
|
-
*
|
|
53
|
+
* Checks if a key exists in the map. Allows for wider literal types for keys
|
|
54
|
+
* during checking.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* const map = IMap.create<'id' | 'enabled', number | boolean>([
|
|
60
|
+
* ['id', 42],
|
|
61
|
+
* ['enabled', true],
|
|
62
|
+
* ]);
|
|
63
|
+
*
|
|
64
|
+
* assert.ok(map.has('id'));
|
|
65
|
+
* assert.notOk(map.has('missing'));
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
53
68
|
* @param key The key to check.
|
|
54
69
|
* @returns `true` if the key exists, `false` otherwise.
|
|
55
70
|
*/
|
|
@@ -57,8 +72,19 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
57
72
|
|
|
58
73
|
/**
|
|
59
74
|
* Retrieves the value associated with a key.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
*
|
|
78
|
+
* ```ts
|
|
79
|
+
* const map = IMap.create([['user', { id: 1 }]]);
|
|
80
|
+
*
|
|
81
|
+
* assert.deepStrictEqual(map.get('user'), Optional.some({ id: 1 }));
|
|
82
|
+
* assert.deepStrictEqual(map.get('missing'), Optional.none);
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
60
85
|
* @param key The key to retrieve.
|
|
61
|
-
* @returns The value associated with the key wrapped with Optional.some, or
|
|
86
|
+
* @returns The value associated with the key wrapped with Optional.some, or
|
|
87
|
+
* `Optional.none` if the key does not exist.
|
|
62
88
|
*/
|
|
63
89
|
get: (key: K | (WidenLiteral<K> & {})) => Optional<V>;
|
|
64
90
|
|
|
@@ -66,13 +92,31 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
66
92
|
|
|
67
93
|
/**
|
|
68
94
|
* Checks if all elements in the map satisfy a predicate.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
*
|
|
98
|
+
* ```ts
|
|
99
|
+
* const map = IMap.create([
|
|
100
|
+
* ['a', 2],
|
|
101
|
+
* ['b', 4],
|
|
102
|
+
* ]);
|
|
103
|
+
*
|
|
104
|
+
* const allEven = map.every((value) => value % 2 === 0);
|
|
105
|
+
* const isNarrowed = map.every((value): value is 2 | 4 => value % 2 === 0);
|
|
106
|
+
*
|
|
107
|
+
* assert.ok(allEven);
|
|
108
|
+
* assert.ok(isNarrowed);
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
69
111
|
* @param predicate A function to test each key-value pair.
|
|
70
112
|
* @returns `true` if all elements satisfy the predicate, `false` otherwise.
|
|
71
113
|
*/
|
|
72
114
|
every: ((predicate: (value: V, key: K) => boolean) => boolean) &
|
|
73
115
|
/**
|
|
74
|
-
* Checks if all elements in the map satisfy a type predicate.
|
|
75
|
-
*
|
|
116
|
+
* Checks if all elements in the map satisfy a type predicate. Narrows the
|
|
117
|
+
* type of values in the map if the predicate returns true for all
|
|
118
|
+
* elements.
|
|
119
|
+
*
|
|
76
120
|
* @template W The narrowed type of the values.
|
|
77
121
|
* @param predicate A type predicate function.
|
|
78
122
|
* @returns `true` if all elements satisfy the predicate, `false` otherwise.
|
|
@@ -83,14 +127,48 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
83
127
|
|
|
84
128
|
/**
|
|
85
129
|
* Checks if at least one element in the map satisfies a predicate.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
*
|
|
133
|
+
* ```ts
|
|
134
|
+
* const entries = [
|
|
135
|
+
* ['alice', 3],
|
|
136
|
+
* ['bob', 5],
|
|
137
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
138
|
+
*
|
|
139
|
+
* const map = IMap.create(entries);
|
|
140
|
+
*
|
|
141
|
+
* assert.ok(map.some((value) => value > 4));
|
|
142
|
+
* assert.notOk(map.some((value) => value > 10));
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
86
145
|
* @param predicate A function to test each key-value pair.
|
|
87
|
-
* @returns `true` if at least one element satisfies the predicate, `false`
|
|
146
|
+
* @returns `true` if at least one element satisfies the predicate, `false`
|
|
147
|
+
* otherwise.
|
|
88
148
|
*/
|
|
89
149
|
some: (predicate: (value: V, key: K) => boolean) => boolean;
|
|
90
150
|
|
|
91
151
|
// Mutation
|
|
152
|
+
|
|
92
153
|
/**
|
|
93
154
|
* Deletes a key-value pair from the map.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
*
|
|
158
|
+
* ```ts
|
|
159
|
+
* const original = IMap.create([
|
|
160
|
+
* ['a', 1],
|
|
161
|
+
* ['b', 2],
|
|
162
|
+
* ]);
|
|
163
|
+
*
|
|
164
|
+
* const withoutB = original.delete('b');
|
|
165
|
+
*
|
|
166
|
+
* assert.deepStrictEqual(original.get('b'), Optional.some(2));
|
|
167
|
+
* assert.deepStrictEqual(withoutB.get('b'), Optional.none);
|
|
168
|
+
* assert(original.size === 2);
|
|
169
|
+
* assert(withoutB.size === 1);
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
94
172
|
* @param key The key to delete.
|
|
95
173
|
* @returns A new IMap instance without the specified key.
|
|
96
174
|
*/
|
|
@@ -98,6 +176,25 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
98
176
|
|
|
99
177
|
/**
|
|
100
178
|
* Sets a key-value pair in the map.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
*
|
|
182
|
+
* ```ts
|
|
183
|
+
* const entries = [['count', 1]] satisfies readonly (readonly [
|
|
184
|
+
* 'count' | 'status',
|
|
185
|
+
* number | string,
|
|
186
|
+
* ])[];
|
|
187
|
+
*
|
|
188
|
+
* const base = IMap.create<'count' | 'status', number | string>(entries);
|
|
189
|
+
*
|
|
190
|
+
* const updated = base.set('count', 2);
|
|
191
|
+
* const extended = base.set('status', 'ok');
|
|
192
|
+
*
|
|
193
|
+
* assert.deepStrictEqual(base.get('count'), Optional.some(1));
|
|
194
|
+
* assert.deepStrictEqual(updated.get('count'), Optional.some(2));
|
|
195
|
+
* assert.deepStrictEqual(extended.get('status'), Optional.some('ok'));
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
101
198
|
* @param key The key to set.
|
|
102
199
|
* @param value The value to associate with the key.
|
|
103
200
|
* @returns A new IMap instance with the specified key-value pair.
|
|
@@ -106,14 +203,63 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
106
203
|
|
|
107
204
|
/**
|
|
108
205
|
* Updates the value associated with a key using an updater function.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
*
|
|
209
|
+
* ```ts
|
|
210
|
+
* const entries = [
|
|
211
|
+
* ['alice', 10],
|
|
212
|
+
* ['bob', 8],
|
|
213
|
+
* ] satisfies readonly (readonly ['alice' | 'bob' | 'charlie', number])[];
|
|
214
|
+
*
|
|
215
|
+
* const scores = IMap.create<'alice' | 'bob' | 'charlie', number>(entries);
|
|
216
|
+
*
|
|
217
|
+
* const boosted = scores.update('alice', (value) => value + 5);
|
|
218
|
+
* const unchanged = scores.update('charlie', (value) => value + 1);
|
|
219
|
+
*
|
|
220
|
+
* assert.deepStrictEqual(boosted.get('alice'), Optional.some(15));
|
|
221
|
+
* assert.deepStrictEqual(scores.get('alice'), Optional.some(10));
|
|
222
|
+
* assert(unchanged === scores);
|
|
223
|
+
* ```
|
|
224
|
+
*
|
|
109
225
|
* @param key The key whose value to update.
|
|
110
|
-
* @param updater A function that takes the current value and returns the new
|
|
226
|
+
* @param updater A function that takes the current value and returns the new
|
|
227
|
+
* value.
|
|
111
228
|
* @returns A new IMap instance with the updated value.
|
|
112
229
|
*/
|
|
113
230
|
update: (key: K, updater: (value: V) => V) => IMap<K, V>;
|
|
114
231
|
|
|
115
232
|
/**
|
|
116
233
|
* Applies a series of mutations to the map.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
*
|
|
237
|
+
* ```ts
|
|
238
|
+
* const entries = [
|
|
239
|
+
* ['a', 1],
|
|
240
|
+
* ['b', 2],
|
|
241
|
+
* ] satisfies readonly (readonly ['a' | 'b' | 'c', number])[];
|
|
242
|
+
*
|
|
243
|
+
* const base = IMap.create<'a' | 'b' | 'c', number>(entries);
|
|
244
|
+
*
|
|
245
|
+
* const actions: readonly Readonly<
|
|
246
|
+
* | { type: 'set'; key: 'c'; value: number }
|
|
247
|
+
* | { type: 'update'; key: 'b'; updater: (value: number) => number }
|
|
248
|
+
* | { type: 'delete'; key: 'a' }
|
|
249
|
+
* >[] = [
|
|
250
|
+
* { type: 'set', key: 'c', value: 3 },
|
|
251
|
+
* { type: 'update', key: 'b', updater: (value) => value * 10 },
|
|
252
|
+
* { type: 'delete', key: 'a' },
|
|
253
|
+
* ];
|
|
254
|
+
*
|
|
255
|
+
* const mutated = base.withMutations(actions);
|
|
256
|
+
*
|
|
257
|
+
* assert.deepStrictEqual(mutated.get('c'), Optional.some(3));
|
|
258
|
+
* assert.deepStrictEqual(mutated.get('b'), Optional.some(20));
|
|
259
|
+
* assert.deepStrictEqual(mutated.get('a'), Optional.none);
|
|
260
|
+
* assert.deepStrictEqual(base.get('b'), Optional.some(2));
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
117
263
|
* @param actions An array of mutation actions (delete, set, or update).
|
|
118
264
|
* @returns A new IMap instance with all mutations applied.
|
|
119
265
|
*/
|
|
@@ -129,6 +275,25 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
129
275
|
|
|
130
276
|
/**
|
|
131
277
|
* Maps the values of the map to new values.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
*
|
|
281
|
+
* ```ts
|
|
282
|
+
* const entries = [
|
|
283
|
+
* ['a', 1],
|
|
284
|
+
* ['b', 2],
|
|
285
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
286
|
+
*
|
|
287
|
+
* const map = IMap.create(entries);
|
|
288
|
+
*
|
|
289
|
+
* const doubled = map.map((value) => value * 2);
|
|
290
|
+
*
|
|
291
|
+
* assert.deepStrictEqual(Array.from(doubled), [
|
|
292
|
+
* ['a', 2],
|
|
293
|
+
* ['b', 4],
|
|
294
|
+
* ]);
|
|
295
|
+
* ```
|
|
296
|
+
*
|
|
132
297
|
* @template V2 The type of the new values.
|
|
133
298
|
* @param mapFn A function that maps a value and key to a new value.
|
|
134
299
|
* @returns A new IMap instance with mapped values.
|
|
@@ -137,6 +302,25 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
137
302
|
|
|
138
303
|
/**
|
|
139
304
|
* Maps the keys of the map to new keys.
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
*
|
|
308
|
+
* ```ts
|
|
309
|
+
* const entries = [
|
|
310
|
+
* ['first', 1],
|
|
311
|
+
* ['second', 2],
|
|
312
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
313
|
+
*
|
|
314
|
+
* const map = IMap.create(entries);
|
|
315
|
+
*
|
|
316
|
+
* const upperKeys = map.mapKeys((key) => key.toUpperCase());
|
|
317
|
+
*
|
|
318
|
+
* assert.deepStrictEqual(Array.from(upperKeys), [
|
|
319
|
+
* ['FIRST', 1],
|
|
320
|
+
* ['SECOND', 2],
|
|
321
|
+
* ]);
|
|
322
|
+
* ```
|
|
323
|
+
*
|
|
140
324
|
* @template K2 The type of the new keys.
|
|
141
325
|
* @param mapFn A function that maps a key to a new key.
|
|
142
326
|
* @returns A new IMap instance with mapped keys and original values.
|
|
@@ -145,6 +329,27 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
145
329
|
|
|
146
330
|
/**
|
|
147
331
|
* Maps the entries (key-value pairs) of the map to new entries.
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
*
|
|
335
|
+
* ```ts
|
|
336
|
+
* const entries = [
|
|
337
|
+
* ['a', 1],
|
|
338
|
+
* ['b', 2],
|
|
339
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
340
|
+
*
|
|
341
|
+
* const map = IMap.create(entries);
|
|
342
|
+
*
|
|
343
|
+
* const swapped = map.mapEntries(
|
|
344
|
+
* ([key, value]) => [value, key] satisfies readonly [number, string],
|
|
345
|
+
* );
|
|
346
|
+
*
|
|
347
|
+
* assert.deepStrictEqual(Array.from(swapped), [
|
|
348
|
+
* [1, 'a'],
|
|
349
|
+
* [2, 'b'],
|
|
350
|
+
* ]);
|
|
351
|
+
* ```
|
|
352
|
+
*
|
|
148
353
|
* @template K2 The type of the new keys in the entries.
|
|
149
354
|
* @template V2 The type of the new values in the entries.
|
|
150
355
|
* @param mapFn A function that maps an entry to a new entry.
|
|
@@ -158,25 +363,96 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
158
363
|
|
|
159
364
|
/**
|
|
160
365
|
* Executes a callback function for each key-value pair in the map.
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
*
|
|
369
|
+
* ```ts
|
|
370
|
+
* const map = IMap.create([
|
|
371
|
+
* ['a', 1],
|
|
372
|
+
* ['b', 2],
|
|
373
|
+
* ]);
|
|
374
|
+
*
|
|
375
|
+
* const entries: (readonly [string, number])[] = [];
|
|
376
|
+
*
|
|
377
|
+
* for (const [key, value] of map.entries()) {
|
|
378
|
+
* entries.push([key, value]);
|
|
379
|
+
* }
|
|
380
|
+
*
|
|
381
|
+
* assert.deepStrictEqual(entries, [
|
|
382
|
+
* ['a', 1],
|
|
383
|
+
* ['b', 2],
|
|
384
|
+
* ]);
|
|
385
|
+
* ```
|
|
386
|
+
*
|
|
161
387
|
* @param callbackfn A function to execute for each element.
|
|
162
388
|
*/
|
|
163
389
|
forEach: (callbackfn: (value: V, key: K) => void) => void;
|
|
164
390
|
|
|
165
391
|
// Iterators
|
|
392
|
+
|
|
166
393
|
/**
|
|
167
394
|
* Returns an iterator for the keys in the map.
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
*
|
|
398
|
+
* ```ts
|
|
399
|
+
* const entries = [
|
|
400
|
+
* ['a', 1],
|
|
401
|
+
* ['b', 2],
|
|
402
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
403
|
+
*
|
|
404
|
+
* const map = IMap.create(entries);
|
|
405
|
+
*
|
|
406
|
+
* const keys = Array.from(map.keys());
|
|
407
|
+
*
|
|
408
|
+
* assert.deepStrictEqual(keys, ['a', 'b']);
|
|
409
|
+
* ```
|
|
410
|
+
*
|
|
168
411
|
* @returns An iterable iterator of keys.
|
|
169
412
|
*/
|
|
170
413
|
keys: () => IterableIterator<K>;
|
|
171
414
|
|
|
172
415
|
/**
|
|
173
416
|
* Returns an iterator for the values in the map.
|
|
417
|
+
*
|
|
418
|
+
* @example
|
|
419
|
+
*
|
|
420
|
+
* ```ts
|
|
421
|
+
* const entries = [
|
|
422
|
+
* ['a', 1],
|
|
423
|
+
* ['b', 2],
|
|
424
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
425
|
+
*
|
|
426
|
+
* const map = IMap.create(entries);
|
|
427
|
+
*
|
|
428
|
+
* const values = Array.from(map.values());
|
|
429
|
+
*
|
|
430
|
+
* assert.deepStrictEqual(values, [1, 2]);
|
|
431
|
+
* ```
|
|
432
|
+
*
|
|
174
433
|
* @returns An iterable iterator of values.
|
|
175
434
|
*/
|
|
176
435
|
values: () => IterableIterator<V>;
|
|
177
436
|
|
|
178
437
|
/**
|
|
179
438
|
* Returns an iterator for the entries (key-value pairs) in the map.
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
*
|
|
442
|
+
* ```ts
|
|
443
|
+
* const map = IMap.create([
|
|
444
|
+
* ['a', 1],
|
|
445
|
+
* ['b', 2],
|
|
446
|
+
* ]);
|
|
447
|
+
*
|
|
448
|
+
* const entries = Array.from(map.entries());
|
|
449
|
+
*
|
|
450
|
+
* assert.deepStrictEqual(entries, [
|
|
451
|
+
* ['a', 1],
|
|
452
|
+
* ['b', 2],
|
|
453
|
+
* ]);
|
|
454
|
+
* ```
|
|
455
|
+
*
|
|
180
456
|
* @returns An iterable iterator of entries.
|
|
181
457
|
*/
|
|
182
458
|
entries: () => IterableIterator<readonly [K, V]>;
|
|
@@ -185,51 +461,130 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
185
461
|
|
|
186
462
|
/**
|
|
187
463
|
* Converts the keys of the map to an array.
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
*
|
|
467
|
+
* ```ts
|
|
468
|
+
* const entries = [
|
|
469
|
+
* ['x', 10],
|
|
470
|
+
* ['y', 20],
|
|
471
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
472
|
+
*
|
|
473
|
+
* const map = IMap.create(entries);
|
|
474
|
+
*
|
|
475
|
+
* assert.deepStrictEqual(map.toKeysArray(), ['x', 'y']);
|
|
476
|
+
* ```
|
|
477
|
+
*
|
|
188
478
|
* @returns A readonly array of keys.
|
|
189
479
|
*/
|
|
190
480
|
toKeysArray: () => readonly K[];
|
|
191
481
|
|
|
192
482
|
/**
|
|
193
483
|
* Converts the values of the map to an array.
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
*
|
|
487
|
+
* ```ts
|
|
488
|
+
* const entries = [
|
|
489
|
+
* ['x', 10],
|
|
490
|
+
* ['y', 20],
|
|
491
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
492
|
+
*
|
|
493
|
+
* const map = IMap.create(entries);
|
|
494
|
+
*
|
|
495
|
+
* assert.deepStrictEqual(map.toValuesArray(), [10, 20]);
|
|
496
|
+
* ```
|
|
497
|
+
*
|
|
194
498
|
* @returns A readonly array of values.
|
|
195
499
|
*/
|
|
196
500
|
toValuesArray: () => readonly V[];
|
|
197
501
|
|
|
198
502
|
/**
|
|
199
503
|
* Converts the entries (key-value pairs) of the map to an array.
|
|
504
|
+
*
|
|
505
|
+
* @example
|
|
506
|
+
*
|
|
507
|
+
* ```ts
|
|
508
|
+
* const entries = [
|
|
509
|
+
* ['a', 1],
|
|
510
|
+
* ['b', 2],
|
|
511
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
512
|
+
*
|
|
513
|
+
* const map = IMap.create(entries);
|
|
514
|
+
*
|
|
515
|
+
* assert.deepStrictEqual(map.toEntriesArray(), [
|
|
516
|
+
* ['a', 1],
|
|
517
|
+
* ['b', 2],
|
|
518
|
+
* ]);
|
|
519
|
+
* ```
|
|
520
|
+
*
|
|
200
521
|
* @returns A readonly array of entries.
|
|
201
522
|
*/
|
|
202
523
|
toEntriesArray: () => readonly (readonly [K, V])[];
|
|
203
524
|
|
|
204
525
|
/**
|
|
205
|
-
* Converts the map to an array of entries (key-value pairs).
|
|
206
|
-
*
|
|
526
|
+
* Converts the map to an array of entries (key-value pairs). Alias for
|
|
527
|
+
* `toEntriesArray`.
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
*
|
|
531
|
+
* ```ts
|
|
532
|
+
* const entries = [
|
|
533
|
+
* ['k1', 'v1'],
|
|
534
|
+
* ['k2', 'v2'],
|
|
535
|
+
* ] satisfies readonly (readonly [string, string])[];
|
|
536
|
+
*
|
|
537
|
+
* const map = IMap.create(entries);
|
|
538
|
+
*
|
|
539
|
+
* assert.deepStrictEqual(map.toArray(), [
|
|
540
|
+
* ['k1', 'v1'],
|
|
541
|
+
* ['k2', 'v2'],
|
|
542
|
+
* ]);
|
|
543
|
+
* ```
|
|
544
|
+
*
|
|
207
545
|
* @returns A readonly array of entries.
|
|
208
546
|
*/
|
|
209
547
|
toArray: () => readonly (readonly [K, V])[];
|
|
210
548
|
|
|
211
549
|
/**
|
|
212
550
|
* Returns the underlying readonly JavaScript Map.
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
*
|
|
554
|
+
* ```ts
|
|
555
|
+
* const entries = [['key', 1]] satisfies readonly (readonly [string, number])[];
|
|
556
|
+
*
|
|
557
|
+
* const map = IMap.create(entries);
|
|
558
|
+
*
|
|
559
|
+
* const raw = map.toRawMap();
|
|
560
|
+
*
|
|
561
|
+
* assert.ok(is.map(raw));
|
|
562
|
+
* assert(raw.get('key') === 1);
|
|
563
|
+
* ```
|
|
564
|
+
*
|
|
213
565
|
* @returns The raw ReadonlyMap instance.
|
|
214
566
|
*/
|
|
215
567
|
toRawMap: () => ReadonlyMap<K, V>;
|
|
216
568
|
}>;
|
|
217
569
|
|
|
218
570
|
/**
|
|
219
|
-
* Represents an immutable map with high-performance operations and functional
|
|
571
|
+
* Represents an immutable map with high-performance operations and functional
|
|
572
|
+
* programming support.
|
|
220
573
|
*
|
|
221
|
-
* IMap is a persistent data structure that provides all the functionality of
|
|
222
|
-
* while maintaining immutability. All operations that would
|
|
223
|
-
* return new IMap instances, making it safe for
|
|
574
|
+
* IMap is a persistent data structure that provides all the functionality of
|
|
575
|
+
* JavaScript's Map while maintaining immutability. All operations that would
|
|
576
|
+
* normally mutate the map instead return new IMap instances, making it safe for
|
|
577
|
+
* functional programming and concurrent access.
|
|
224
578
|
*
|
|
225
579
|
* **Key Features:**
|
|
580
|
+
*
|
|
226
581
|
* - **Immutable**: All mutation operations return new instances
|
|
227
|
-
* - **High Performance**: O(1) average-case for get/set/has/delete operations
|
|
228
582
|
* - **Type Safe**: Full TypeScript support with generic key/value types
|
|
229
583
|
* - **Iterable**: Implements standard JavaScript iteration protocols
|
|
230
584
|
* - **Functional**: Rich API for map, filter, reduce-style operations
|
|
231
585
|
*
|
|
232
586
|
* **When to Use:**
|
|
587
|
+
*
|
|
233
588
|
* - State management in functional applications
|
|
234
589
|
* - Caching with immutable guarantees
|
|
235
590
|
* - Data structures that need to be shared across components
|
|
@@ -237,98 +592,38 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
237
592
|
*
|
|
238
593
|
* @template K The type of the keys in the map. Must extend MapSetKeyType.
|
|
239
594
|
* @template V The type of the values in the map.
|
|
240
|
-
*
|
|
241
|
-
* @example
|
|
242
|
-
* ```typescript
|
|
243
|
-
* // Create an immutable map with initial data
|
|
244
|
-
* let userPreferences = IMap.create<string, UserPreference>([
|
|
245
|
-
* ["theme", { value: "dark", lastModified: Date.now() }],
|
|
246
|
-
* ["language", { value: "en", lastModified: Date.now() }]
|
|
247
|
-
* ]);
|
|
248
|
-
*
|
|
249
|
-
* console.log(userPreferences.get("theme").unwrapOr(defaultPreference));
|
|
250
|
-
* console.log(userPreferences.size); // Output: 2
|
|
251
|
-
*
|
|
252
|
-
* // All operations return new instances - original is unchanged
|
|
253
|
-
* const updated = userPreferences
|
|
254
|
-
* .set("notifications", { value: true, lastModified: Date.now() })
|
|
255
|
-
* .update("theme", pref => ({ ...pref, value: "light" }));
|
|
256
|
-
*
|
|
257
|
-
* console.log(userPreferences.has("notifications")); // false (original unchanged)
|
|
258
|
-
* console.log(updated.has("notifications")); // true (new instance)
|
|
259
|
-
*
|
|
260
|
-
* // Efficient iteration and transformation
|
|
261
|
-
* for (const [key, preference] of updated) {
|
|
262
|
-
* console.log(`${key}: ${preference.value}`);
|
|
263
|
-
* }
|
|
264
|
-
*
|
|
265
|
-
* // Functional transformations
|
|
266
|
-
* const withTimestamps = updated.map((pref, key) => ({
|
|
267
|
-
* ...pref,
|
|
268
|
-
* accessedAt: Date.now()
|
|
269
|
-
* }));
|
|
270
|
-
*
|
|
271
|
-
* // Type-safe operations with narrowing
|
|
272
|
-
* const stringKeys = IMap.create<number | string, any>([[1, "a"], ["b", 2]]);
|
|
273
|
-
* const onlyStringKeys = stringKeys.mapKeys(key =>
|
|
274
|
-
* typeof key === "string" ? key : key.toString()
|
|
275
|
-
* );
|
|
276
|
-
* ```
|
|
277
595
|
*/
|
|
278
596
|
export type IMap<K extends MapSetKeyType, V> = Iterable<readonly [K, V]> &
|
|
279
597
|
IMapInterface<K, V>;
|
|
280
598
|
|
|
281
|
-
/**
|
|
282
|
-
* Provides utility functions for IMap.
|
|
283
|
-
*/
|
|
599
|
+
/** Provides utility functions for IMap. */
|
|
284
600
|
export namespace IMap {
|
|
285
601
|
/**
|
|
286
602
|
* Creates a new IMap instance from an iterable of key-value pairs.
|
|
287
603
|
*
|
|
288
|
-
* This factory function accepts any iterable of [key, value] tuples,
|
|
289
|
-
* JavaScript Maps, other IMaps, or custom iterables. The
|
|
290
|
-
* all the entries from the input iterable.
|
|
604
|
+
* This factory function accepts any iterable of [key, value] tuples,
|
|
605
|
+
* including arrays, JavaScript Maps, other IMaps, or custom iterables. The
|
|
606
|
+
* resulting IMap will contain all the entries from the input iterable.
|
|
291
607
|
*
|
|
292
608
|
* **Performance:** O(n) where n is the number of entries in the iterable.
|
|
293
609
|
*
|
|
294
|
-
* @template K The type of the keys. Must extend MapSetKeyType.
|
|
295
|
-
* @template V The type of the values.
|
|
296
|
-
* @param iterable An iterable of key-value pairs (e.g., Array, Map, IMap, etc.)
|
|
297
|
-
* @returns A new IMap instance containing all entries from the iterable.
|
|
298
|
-
*
|
|
299
610
|
* @example
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
* const
|
|
303
|
-
* [
|
|
304
|
-
* [
|
|
305
|
-
* ["charlie", 92]
|
|
611
|
+
*
|
|
612
|
+
* ```ts
|
|
613
|
+
* const map = IMap.create<string, number | string>([
|
|
614
|
+
* ['id', 1],
|
|
615
|
+
* ['status', 'active'],
|
|
306
616
|
* ]);
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
* const jsMap = new Map([["config", { debug: true }], ["env", "production"]]);
|
|
311
|
-
* const config = IMap.create(jsMap);
|
|
312
|
-
* console.log(config.get("env").unwrap()); // Output: "production"
|
|
313
|
-
*
|
|
314
|
-
* // From another IMap (creates a copy)
|
|
315
|
-
* const originalMap = IMap.create<string, boolean>([["enabled", true]]);
|
|
316
|
-
* const copiedMap = IMap.create(originalMap);
|
|
317
|
-
* console.log(copiedMap.get("enabled").unwrap()); // Output: true
|
|
318
|
-
*
|
|
319
|
-
* // Empty map
|
|
320
|
-
* const emptyMap = IMap.create<string, number>([]);
|
|
321
|
-
* console.log(emptyMap.size); // Output: 0
|
|
322
|
-
*
|
|
323
|
-
* // From custom iterable
|
|
324
|
-
* function* generateEntries(): Generator<[string, number]> {
|
|
325
|
-
* for (const i of range(3)) {
|
|
326
|
-
* yield [`item${i}`, i * 10];
|
|
327
|
-
* }
|
|
328
|
-
* }
|
|
329
|
-
* const generatedMap = IMap.create(generateEntries());
|
|
330
|
-
* console.log(generatedMap.size); // Output: 3
|
|
617
|
+
*
|
|
618
|
+
* assert(map.size === 2);
|
|
619
|
+
* assert.deepStrictEqual(map.get('status'), Optional.some('active'));
|
|
331
620
|
* ```
|
|
621
|
+
*
|
|
622
|
+
* @template K The type of the keys. Must extend MapSetKeyType.
|
|
623
|
+
* @template V The type of the values.
|
|
624
|
+
* @param iterable An iterable of key-value pairs (e.g., Array, Map, IMap,
|
|
625
|
+
* etc.)
|
|
626
|
+
* @returns A new IMap instance containing all entries from the iterable.
|
|
332
627
|
*/
|
|
333
628
|
export const create = <K extends MapSetKeyType, V>(
|
|
334
629
|
iterable: Iterable<readonly [K, V]>,
|
|
@@ -337,77 +632,64 @@ export namespace IMap {
|
|
|
337
632
|
/**
|
|
338
633
|
* Checks if two IMap instances are structurally equal.
|
|
339
634
|
*
|
|
340
|
-
* Two IMaps are considered equal if they have the same size and contain
|
|
341
|
-
* key-value pairs. The order of entries does not matter for
|
|
342
|
-
* Values are compared using JavaScript's `===`
|
|
635
|
+
* Two IMaps are considered equal if they have the same size and contain
|
|
636
|
+
* exactly the same key-value pairs. The order of entries does not matter for
|
|
637
|
+
* equality comparison. Values are compared using JavaScript's `===`
|
|
638
|
+
* operator.
|
|
343
639
|
*
|
|
344
640
|
* **Performance:** O(n) where n is the size of the smaller map.
|
|
345
641
|
*
|
|
346
|
-
* @template K The type of the keys.
|
|
347
|
-
* @template V The type of the values.
|
|
348
|
-
* @param a The first IMap instance to compare.
|
|
349
|
-
* @param b The second IMap instance to compare.
|
|
350
|
-
* @returns `true` if the maps contain exactly the same key-value pairs, `false` otherwise.
|
|
351
|
-
*
|
|
352
642
|
* @example
|
|
353
|
-
* ```typescript
|
|
354
|
-
* // Basic equality comparison
|
|
355
|
-
* const preferences1 = IMap.create<string, boolean>([
|
|
356
|
-
* ["darkMode", true],
|
|
357
|
-
* ["notifications", false]
|
|
358
|
-
* ]);
|
|
359
|
-
* const preferences2 = IMap.create<string, boolean>([
|
|
360
|
-
* ["darkMode", true],
|
|
361
|
-
* ["notifications", false]
|
|
362
|
-
* ]);
|
|
363
|
-
* const preferences3 = IMap.create<string, boolean>([
|
|
364
|
-
* ["notifications", false],
|
|
365
|
-
* ["darkMode", true] // Order doesn't matter
|
|
366
|
-
* ]);
|
|
367
|
-
*
|
|
368
|
-
* console.log(IMap.equal(preferences1, preferences2)); // true
|
|
369
|
-
* console.log(IMap.equal(preferences1, preferences3)); // true (order doesn't matter)
|
|
370
643
|
*
|
|
371
|
-
*
|
|
372
|
-
* const
|
|
373
|
-
* [
|
|
374
|
-
* [
|
|
644
|
+
* ```ts
|
|
645
|
+
* const first = IMap.create<'a' | 'b', number>([
|
|
646
|
+
* ['a', 1],
|
|
647
|
+
* ['b', 2],
|
|
375
648
|
* ]);
|
|
376
|
-
* console.log(IMap.equal(preferences1, preferences4)); // false
|
|
377
649
|
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
* [
|
|
381
|
-
* ["sounds", false] // Different key
|
|
650
|
+
* const second = IMap.create<'a' | 'b', number>([
|
|
651
|
+
* ['b', 2],
|
|
652
|
+
* ['a', 1],
|
|
382
653
|
* ]);
|
|
383
|
-
* console.log(IMap.equal(preferences1, preferences5)); // false
|
|
384
654
|
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
655
|
+
* const third = IMap.create<'a' | 'b', number>([
|
|
656
|
+
* ['a', 1],
|
|
657
|
+
* ['b', 3],
|
|
658
|
+
* ]);
|
|
389
659
|
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
* const users2 = IMap.create<string, User>([["1", { name: "Alice" }]]);
|
|
393
|
-
* console.log(IMap.equal(users1, users2)); // false (different object references)
|
|
660
|
+
* assert.ok(IMap.equal(first, second));
|
|
661
|
+
* assert.notOk(IMap.equal(first, third));
|
|
394
662
|
* ```
|
|
663
|
+
*
|
|
664
|
+
* @template K The type of the keys.
|
|
665
|
+
* @template V The type of the values.
|
|
666
|
+
* @param a The first IMap instance to compare.
|
|
667
|
+
* @param b The second IMap instance to compare.
|
|
668
|
+
* @returns `true` if the maps contain exactly the same key-value pairs,
|
|
669
|
+
* `false` otherwise.
|
|
395
670
|
*/
|
|
396
671
|
export const equal = <K extends MapSetKeyType, V>(
|
|
397
672
|
a: IMap<K, V>,
|
|
398
673
|
b: IMap<K, V>,
|
|
399
|
-
): boolean =>
|
|
674
|
+
): boolean =>
|
|
675
|
+
a.size === b.size &&
|
|
676
|
+
a.every(
|
|
677
|
+
(v, k) =>
|
|
678
|
+
pipe(b.get(k)).map((v2) => Optional.isSome(v2) && v2.value === v).value,
|
|
679
|
+
);
|
|
400
680
|
}
|
|
401
681
|
|
|
402
682
|
/**
|
|
403
683
|
* Internal class implementation for IMap providing immutable map operations.
|
|
404
684
|
*
|
|
405
|
-
* This class implements the IMap interface using JavaScript's native Map as the
|
|
406
|
-
* storage mechanism for optimal performance. All mutation operations
|
|
407
|
-
* rather than modifying the existing map, ensuring
|
|
685
|
+
* This class implements the IMap interface using JavaScript's native Map as the
|
|
686
|
+
* underlying storage mechanism for optimal performance. All mutation operations
|
|
687
|
+
* create new instances rather than modifying the existing map, ensuring
|
|
688
|
+
* immutability.
|
|
408
689
|
*
|
|
409
690
|
* **Implementation Details:**
|
|
410
|
-
*
|
|
691
|
+
*
|
|
692
|
+
* - Uses Map<K, V> internally for type safety and performance
|
|
411
693
|
* - Implements copy-on-write semantics for efficiency
|
|
412
694
|
* - Provides optional debug messaging for development
|
|
413
695
|
*
|
|
@@ -428,8 +710,8 @@ class IMapClass<K extends MapSetKeyType, V>
|
|
|
428
710
|
*
|
|
429
711
|
* @param iterable An iterable of key-value pairs to populate the map.
|
|
430
712
|
* @param showNotFoundMessage Whether to log warning messages when operations
|
|
431
|
-
*
|
|
432
|
-
*
|
|
713
|
+
* are performed on non-existent keys. Useful for debugging. Defaults to
|
|
714
|
+
* false for production use.
|
|
433
715
|
* @internal Use IMap.create() instead of calling this constructor directly.
|
|
434
716
|
*/
|
|
435
717
|
constructor(
|
|
@@ -447,14 +729,14 @@ class IMapClass<K extends MapSetKeyType, V>
|
|
|
447
729
|
|
|
448
730
|
/** @inheritdoc */
|
|
449
731
|
has(key: K | (WidenLiteral<K> & {})): boolean {
|
|
450
|
-
// eslint-disable-next-line
|
|
732
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
451
733
|
return this.#map.has(key as K);
|
|
452
734
|
}
|
|
453
735
|
|
|
454
736
|
/** @inheritdoc */
|
|
455
737
|
get(key: K | (WidenLiteral<K> & {})): Optional<V> {
|
|
456
738
|
if (!this.has(key)) return Optional.none;
|
|
457
|
-
// eslint-disable-next-line
|
|
739
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, @typescript-eslint/no-non-null-assertion
|
|
458
740
|
return Optional.some(this.#map.get(key as K)!);
|
|
459
741
|
}
|
|
460
742
|
|
|
@@ -462,8 +744,10 @@ class IMapClass<K extends MapSetKeyType, V>
|
|
|
462
744
|
every<W extends V>(
|
|
463
745
|
predicate: (value: V, key: K) => value is W,
|
|
464
746
|
): this is IMap<K, W>;
|
|
747
|
+
|
|
465
748
|
/** @inheritdoc */
|
|
466
749
|
every(predicate: (value: V, key: K) => boolean): boolean;
|
|
750
|
+
|
|
467
751
|
/** @inheritdoc */
|
|
468
752
|
every(predicate: (value: V, key: K) => boolean): boolean {
|
|
469
753
|
for (const [k, v] of this.entries()) {
|
|
@@ -499,7 +783,8 @@ class IMapClass<K extends MapSetKeyType, V>
|
|
|
499
783
|
|
|
500
784
|
/** @inheritdoc */
|
|
501
785
|
set(key: K, value: V): IMap<K, V> {
|
|
502
|
-
|
|
786
|
+
const curr = this.get(key);
|
|
787
|
+
if (Optional.isSome(curr) && value === curr.value) return this; // has no changes
|
|
503
788
|
if (!this.has(key)) {
|
|
504
789
|
return IMap.create([...this.#map, tp(key, value)]);
|
|
505
790
|
} else {
|
|
@@ -596,6 +881,24 @@ class IMapClass<K extends MapSetKeyType, V>
|
|
|
596
881
|
}
|
|
597
882
|
|
|
598
883
|
/**
|
|
884
|
+
* @example
|
|
885
|
+
*
|
|
886
|
+
* ```ts
|
|
887
|
+
* const entries = [
|
|
888
|
+
* ['first', 1],
|
|
889
|
+
* ['second', 2],
|
|
890
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
891
|
+
*
|
|
892
|
+
* const map = IMap.create(entries);
|
|
893
|
+
*
|
|
894
|
+
* const collected = Array.from(map);
|
|
895
|
+
*
|
|
896
|
+
* assert.deepStrictEqual(collected, [
|
|
897
|
+
* ['first', 1],
|
|
898
|
+
* ['second', 2],
|
|
899
|
+
* ]);
|
|
900
|
+
* ```
|
|
901
|
+
*
|
|
599
902
|
* @inheritdoc
|
|
600
903
|
*/
|
|
601
904
|
[Symbol.iterator](): Iterator<readonly [K, V]> {
|