ts-data-forge 1.0.0 → 1.0.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.
Files changed (292) hide show
  1. package/README.md +1 -1
  2. package/dist/array/array-utils.d.mts +2617 -0
  3. package/dist/array/array-utils.d.mts.map +1 -0
  4. package/dist/array/array-utils.mjs +2915 -0
  5. package/dist/array/array-utils.mjs.map +1 -0
  6. package/dist/array/index.d.mts +3 -0
  7. package/dist/array/index.d.mts.map +1 -0
  8. package/dist/array/index.mjs +3 -0
  9. package/dist/array/index.mjs.map +1 -0
  10. package/dist/array/tuple-utils.d.mts +421 -0
  11. package/dist/array/tuple-utils.d.mts.map +1 -0
  12. package/dist/array/tuple-utils.mjs +391 -0
  13. package/dist/array/tuple-utils.mjs.map +1 -0
  14. package/dist/collections/imap-mapped.d.mts +445 -0
  15. package/dist/collections/imap-mapped.d.mts.map +1 -0
  16. package/dist/collections/imap-mapped.mjs +424 -0
  17. package/dist/collections/imap-mapped.mjs.map +1 -0
  18. package/dist/collections/imap.d.mts +359 -0
  19. package/dist/collections/imap.d.mts.map +1 -0
  20. package/dist/collections/imap.mjs +338 -0
  21. package/dist/collections/imap.mjs.map +1 -0
  22. package/dist/collections/index.d.mts +7 -0
  23. package/dist/collections/index.d.mts.map +1 -0
  24. package/dist/collections/index.mjs +7 -0
  25. package/dist/collections/index.mjs.map +1 -0
  26. package/dist/collections/iset-mapped.d.mts +576 -0
  27. package/dist/collections/iset-mapped.d.mts.map +1 -0
  28. package/dist/collections/iset-mapped.mjs +522 -0
  29. package/dist/collections/iset-mapped.mjs.map +1 -0
  30. package/dist/collections/iset.d.mts +426 -0
  31. package/dist/collections/iset.d.mts.map +1 -0
  32. package/dist/collections/iset.mjs +437 -0
  33. package/dist/collections/iset.mjs.map +1 -0
  34. package/dist/collections/queue.d.mts +190 -0
  35. package/dist/collections/queue.d.mts.map +1 -0
  36. package/dist/collections/queue.mjs +317 -0
  37. package/dist/collections/queue.mjs.map +1 -0
  38. package/dist/collections/stack.d.mts +210 -0
  39. package/dist/collections/stack.d.mts.map +1 -0
  40. package/dist/collections/stack.mjs +353 -0
  41. package/dist/collections/stack.mjs.map +1 -0
  42. package/dist/expect-type.d.mts +199 -0
  43. package/dist/expect-type.d.mts.map +1 -0
  44. package/dist/expect-type.mjs +201 -0
  45. package/dist/expect-type.mjs.map +1 -0
  46. package/dist/functional/index.d.mts +5 -0
  47. package/dist/functional/index.d.mts.map +1 -0
  48. package/dist/functional/index.mjs +5 -0
  49. package/dist/functional/index.mjs.map +1 -0
  50. package/dist/functional/match.d.mts +215 -0
  51. package/dist/functional/match.d.mts.map +1 -0
  52. package/dist/functional/match.mjs +139 -0
  53. package/dist/functional/match.mjs.map +1 -0
  54. package/dist/functional/optional.d.mts +517 -0
  55. package/dist/functional/optional.d.mts.map +1 -0
  56. package/dist/functional/optional.mjs +532 -0
  57. package/dist/functional/optional.mjs.map +1 -0
  58. package/dist/functional/pipe.d.mts +185 -0
  59. package/dist/functional/pipe.d.mts.map +1 -0
  60. package/dist/functional/pipe.mjs +129 -0
  61. package/dist/functional/pipe.mjs.map +1 -0
  62. package/dist/functional/result.d.mts +796 -0
  63. package/dist/functional/result.d.mts.map +1 -0
  64. package/dist/functional/result.mjs +844 -0
  65. package/dist/functional/result.mjs.map +1 -0
  66. package/dist/globals.d.mts +38 -0
  67. package/dist/guard/has-key.d.mts +100 -0
  68. package/dist/guard/has-key.d.mts.map +1 -0
  69. package/dist/guard/has-key.mjs +94 -0
  70. package/dist/guard/has-key.mjs.map +1 -0
  71. package/dist/guard/index.d.mts +8 -0
  72. package/dist/guard/index.d.mts.map +1 -0
  73. package/dist/guard/index.mjs +8 -0
  74. package/dist/guard/index.mjs.map +1 -0
  75. package/dist/guard/is-non-empty-string.d.mts +106 -0
  76. package/dist/guard/is-non-empty-string.d.mts.map +1 -0
  77. package/dist/guard/is-non-empty-string.mjs +108 -0
  78. package/dist/guard/is-non-empty-string.mjs.map +1 -0
  79. package/dist/guard/is-non-null-object.d.mts +105 -0
  80. package/dist/guard/is-non-null-object.d.mts.map +1 -0
  81. package/dist/guard/is-non-null-object.mjs +108 -0
  82. package/dist/guard/is-non-null-object.mjs.map +1 -0
  83. package/dist/guard/is-primitive.d.mts +146 -0
  84. package/dist/guard/is-primitive.d.mts.map +1 -0
  85. package/dist/guard/is-primitive.mjs +161 -0
  86. package/dist/guard/is-primitive.mjs.map +1 -0
  87. package/dist/guard/is-record.d.mts +151 -0
  88. package/dist/guard/is-record.d.mts.map +1 -0
  89. package/dist/guard/is-record.mjs +155 -0
  90. package/dist/guard/is-record.mjs.map +1 -0
  91. package/dist/guard/is-type.d.mts +430 -0
  92. package/dist/guard/is-type.d.mts.map +1 -0
  93. package/dist/guard/is-type.mjs +432 -0
  94. package/dist/guard/is-type.mjs.map +1 -0
  95. package/dist/guard/key-is-in.d.mts +158 -0
  96. package/dist/guard/key-is-in.d.mts.map +1 -0
  97. package/dist/guard/key-is-in.mjs +160 -0
  98. package/dist/guard/key-is-in.mjs.map +1 -0
  99. package/dist/index.d.mts +11 -0
  100. package/dist/index.d.mts.map +1 -0
  101. package/dist/index.mjs +61 -0
  102. package/dist/index.mjs.map +1 -0
  103. package/dist/iterator/index.d.mts +2 -0
  104. package/dist/iterator/index.d.mts.map +1 -0
  105. package/dist/iterator/index.mjs +2 -0
  106. package/dist/iterator/index.mjs.map +1 -0
  107. package/dist/iterator/range.d.mts +97 -0
  108. package/dist/iterator/range.d.mts.map +1 -0
  109. package/dist/iterator/range.mjs +130 -0
  110. package/dist/iterator/range.mjs.map +1 -0
  111. package/dist/json/index.d.mts +2 -0
  112. package/dist/json/index.d.mts.map +1 -0
  113. package/dist/json/index.mjs +2 -0
  114. package/dist/json/index.mjs.map +1 -0
  115. package/dist/json/json.d.mts +597 -0
  116. package/dist/json/json.d.mts.map +1 -0
  117. package/dist/json/json.mjs +687 -0
  118. package/dist/json/json.mjs.map +1 -0
  119. package/dist/number/branded-types/finite-number.d.mts +291 -0
  120. package/dist/number/branded-types/finite-number.d.mts.map +1 -0
  121. package/dist/number/branded-types/finite-number.mjs +296 -0
  122. package/dist/number/branded-types/finite-number.mjs.map +1 -0
  123. package/dist/number/branded-types/index.d.mts +27 -0
  124. package/dist/number/branded-types/index.d.mts.map +1 -0
  125. package/dist/number/branded-types/index.mjs +27 -0
  126. package/dist/number/branded-types/index.mjs.map +1 -0
  127. package/dist/number/branded-types/int.d.mts +242 -0
  128. package/dist/number/branded-types/int.d.mts.map +1 -0
  129. package/dist/number/branded-types/int.mjs +239 -0
  130. package/dist/number/branded-types/int.mjs.map +1 -0
  131. package/dist/number/branded-types/int16.d.mts +162 -0
  132. package/dist/number/branded-types/int16.d.mts.map +1 -0
  133. package/dist/number/branded-types/int16.mjs +141 -0
  134. package/dist/number/branded-types/int16.mjs.map +1 -0
  135. package/dist/number/branded-types/int32.d.mts +155 -0
  136. package/dist/number/branded-types/int32.d.mts.map +1 -0
  137. package/dist/number/branded-types/int32.mjs +142 -0
  138. package/dist/number/branded-types/int32.mjs.map +1 -0
  139. package/dist/number/branded-types/non-negative-finite-number.d.mts +165 -0
  140. package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -0
  141. package/dist/number/branded-types/non-negative-finite-number.mjs +160 -0
  142. package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -0
  143. package/dist/number/branded-types/non-negative-int16.d.mts +160 -0
  144. package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -0
  145. package/dist/number/branded-types/non-negative-int16.mjs +138 -0
  146. package/dist/number/branded-types/non-negative-int16.mjs.map +1 -0
  147. package/dist/number/branded-types/non-negative-int32.d.mts +156 -0
  148. package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -0
  149. package/dist/number/branded-types/non-negative-int32.mjs +138 -0
  150. package/dist/number/branded-types/non-negative-int32.mjs.map +1 -0
  151. package/dist/number/branded-types/non-zero-finite-number.d.mts +154 -0
  152. package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -0
  153. package/dist/number/branded-types/non-zero-finite-number.mjs +160 -0
  154. package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -0
  155. package/dist/number/branded-types/non-zero-int.d.mts +131 -0
  156. package/dist/number/branded-types/non-zero-int.d.mts.map +1 -0
  157. package/dist/number/branded-types/non-zero-int.mjs +128 -0
  158. package/dist/number/branded-types/non-zero-int.mjs.map +1 -0
  159. package/dist/number/branded-types/non-zero-int16.d.mts +166 -0
  160. package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -0
  161. package/dist/number/branded-types/non-zero-int16.mjs +145 -0
  162. package/dist/number/branded-types/non-zero-int16.mjs.map +1 -0
  163. package/dist/number/branded-types/non-zero-int32.d.mts +158 -0
  164. package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -0
  165. package/dist/number/branded-types/non-zero-int32.mjs +145 -0
  166. package/dist/number/branded-types/non-zero-int32.mjs.map +1 -0
  167. package/dist/number/branded-types/non-zero-safe-int.d.mts +148 -0
  168. package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -0
  169. package/dist/number/branded-types/non-zero-safe-int.mjs +145 -0
  170. package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -0
  171. package/dist/number/branded-types/non-zero-uint16.d.mts +160 -0
  172. package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -0
  173. package/dist/number/branded-types/non-zero-uint16.mjs +140 -0
  174. package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -0
  175. package/dist/number/branded-types/non-zero-uint32.d.mts +156 -0
  176. package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -0
  177. package/dist/number/branded-types/non-zero-uint32.mjs +140 -0
  178. package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -0
  179. package/dist/number/branded-types/positive-finite-number.d.mts +171 -0
  180. package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -0
  181. package/dist/number/branded-types/positive-finite-number.mjs +165 -0
  182. package/dist/number/branded-types/positive-finite-number.mjs.map +1 -0
  183. package/dist/number/branded-types/positive-int.d.mts +270 -0
  184. package/dist/number/branded-types/positive-int.d.mts.map +1 -0
  185. package/dist/number/branded-types/positive-int.mjs +257 -0
  186. package/dist/number/branded-types/positive-int.mjs.map +1 -0
  187. package/dist/number/branded-types/positive-int16.d.mts +162 -0
  188. package/dist/number/branded-types/positive-int16.d.mts.map +1 -0
  189. package/dist/number/branded-types/positive-int16.mjs +139 -0
  190. package/dist/number/branded-types/positive-int16.mjs.map +1 -0
  191. package/dist/number/branded-types/positive-int32.d.mts +158 -0
  192. package/dist/number/branded-types/positive-int32.d.mts.map +1 -0
  193. package/dist/number/branded-types/positive-int32.mjs +139 -0
  194. package/dist/number/branded-types/positive-int32.mjs.map +1 -0
  195. package/dist/number/branded-types/positive-safe-int.d.mts +152 -0
  196. package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -0
  197. package/dist/number/branded-types/positive-safe-int.mjs +138 -0
  198. package/dist/number/branded-types/positive-safe-int.mjs.map +1 -0
  199. package/dist/number/branded-types/positive-uint16.d.mts +160 -0
  200. package/dist/number/branded-types/positive-uint16.d.mts.map +1 -0
  201. package/dist/number/branded-types/positive-uint16.mjs +139 -0
  202. package/dist/number/branded-types/positive-uint16.mjs.map +1 -0
  203. package/dist/number/branded-types/positive-uint32.d.mts +156 -0
  204. package/dist/number/branded-types/positive-uint32.d.mts.map +1 -0
  205. package/dist/number/branded-types/positive-uint32.mjs +139 -0
  206. package/dist/number/branded-types/positive-uint32.mjs.map +1 -0
  207. package/dist/number/branded-types/safe-int.d.mts +243 -0
  208. package/dist/number/branded-types/safe-int.d.mts.map +1 -0
  209. package/dist/number/branded-types/safe-int.mjs +240 -0
  210. package/dist/number/branded-types/safe-int.mjs.map +1 -0
  211. package/dist/number/branded-types/safe-uint.d.mts +151 -0
  212. package/dist/number/branded-types/safe-uint.d.mts.map +1 -0
  213. package/dist/number/branded-types/safe-uint.mjs +138 -0
  214. package/dist/number/branded-types/safe-uint.mjs.map +1 -0
  215. package/dist/number/branded-types/uint.d.mts +144 -0
  216. package/dist/number/branded-types/uint.d.mts.map +1 -0
  217. package/dist/number/branded-types/uint.mjs +132 -0
  218. package/dist/number/branded-types/uint.mjs.map +1 -0
  219. package/dist/number/branded-types/uint16.d.mts +157 -0
  220. package/dist/number/branded-types/uint16.d.mts.map +1 -0
  221. package/dist/number/branded-types/uint16.mjs +137 -0
  222. package/dist/number/branded-types/uint16.mjs.map +1 -0
  223. package/dist/number/branded-types/uint32.d.mts +185 -0
  224. package/dist/number/branded-types/uint32.d.mts.map +1 -0
  225. package/dist/number/branded-types/uint32.mjs +169 -0
  226. package/dist/number/branded-types/uint32.mjs.map +1 -0
  227. package/dist/number/enum/index.d.mts +3 -0
  228. package/dist/number/enum/index.d.mts.map +1 -0
  229. package/dist/number/enum/index.mjs +3 -0
  230. package/dist/number/enum/index.mjs.map +1 -0
  231. package/dist/number/enum/int8.d.mts +202 -0
  232. package/dist/number/enum/int8.d.mts.map +1 -0
  233. package/dist/number/enum/int8.mjs +296 -0
  234. package/dist/number/enum/int8.mjs.map +1 -0
  235. package/dist/number/enum/uint8.d.mts +128 -0
  236. package/dist/number/enum/uint8.d.mts.map +1 -0
  237. package/dist/number/enum/uint8.mjs +251 -0
  238. package/dist/number/enum/uint8.mjs.map +1 -0
  239. package/dist/number/index.d.mts +5 -0
  240. package/dist/number/index.d.mts.map +1 -0
  241. package/dist/number/index.mjs +31 -0
  242. package/dist/number/index.mjs.map +1 -0
  243. package/dist/number/num.d.mts +515 -0
  244. package/dist/number/num.d.mts.map +1 -0
  245. package/dist/number/num.mjs +513 -0
  246. package/dist/number/num.mjs.map +1 -0
  247. package/dist/number/refined-number-utils.d.mts +191 -0
  248. package/dist/number/refined-number-utils.d.mts.map +1 -0
  249. package/dist/number/refined-number-utils.mjs +179 -0
  250. package/dist/number/refined-number-utils.mjs.map +1 -0
  251. package/dist/object/index.d.mts +2 -0
  252. package/dist/object/index.d.mts.map +1 -0
  253. package/dist/object/index.mjs +2 -0
  254. package/dist/object/index.mjs.map +1 -0
  255. package/dist/object/object.d.mts +296 -0
  256. package/dist/object/object.d.mts.map +1 -0
  257. package/dist/object/object.mjs +295 -0
  258. package/dist/object/object.mjs.map +1 -0
  259. package/dist/others/cast-mutable.d.mts +110 -0
  260. package/dist/others/cast-mutable.d.mts.map +1 -0
  261. package/dist/others/cast-mutable.mjs +114 -0
  262. package/dist/others/cast-mutable.mjs.map +1 -0
  263. package/dist/others/cast-readonly.d.mts +189 -0
  264. package/dist/others/cast-readonly.d.mts.map +1 -0
  265. package/dist/others/cast-readonly.mjs +193 -0
  266. package/dist/others/cast-readonly.mjs.map +1 -0
  267. package/dist/others/if-then.d.mts +98 -0
  268. package/dist/others/if-then.d.mts.map +1 -0
  269. package/dist/others/if-then.mjs +100 -0
  270. package/dist/others/if-then.mjs.map +1 -0
  271. package/dist/others/index.d.mts +8 -0
  272. package/dist/others/index.d.mts.map +1 -0
  273. package/dist/others/index.mjs +8 -0
  274. package/dist/others/index.mjs.map +1 -0
  275. package/dist/others/map-nullable.d.mts +151 -0
  276. package/dist/others/map-nullable.d.mts.map +1 -0
  277. package/dist/others/map-nullable.mjs +159 -0
  278. package/dist/others/map-nullable.mjs.map +1 -0
  279. package/dist/others/memoize-function.d.mts +173 -0
  280. package/dist/others/memoize-function.d.mts.map +1 -0
  281. package/dist/others/memoize-function.mjs +189 -0
  282. package/dist/others/memoize-function.mjs.map +1 -0
  283. package/dist/others/tuple.d.mts +159 -0
  284. package/dist/others/tuple.d.mts.map +1 -0
  285. package/dist/others/tuple.mjs +161 -0
  286. package/dist/others/tuple.mjs.map +1 -0
  287. package/dist/others/unknown-to-string.d.mts +180 -0
  288. package/dist/others/unknown-to-string.d.mts.map +1 -0
  289. package/dist/others/unknown-to-string.mjs +211 -0
  290. package/dist/others/unknown-to-string.mjs.map +1 -0
  291. package/dist/tsconfig.json +1 -0
  292. package/package.json +16 -14
@@ -0,0 +1,359 @@
1
+ import { Optional } from '../functional/index.mjs';
2
+ /**
3
+ * Interface for an immutable map with O(1) lookup performance and functional programming patterns.
4
+ *
5
+ * This interface defines all methods and properties available on IMap instances. All operations
6
+ * that modify the map return new IMap instances, preserving immutability. The underlying implementation
7
+ * uses JavaScript's native Map for O(1) average-case performance on get, set, has, and delete operations.
8
+ *
9
+ * **Immutability Guarantees:**
10
+ * - All mutation operations (set, delete, update) return new IMap instances
11
+ * - Original IMap instances are never modified
12
+ * - Safe for concurrent access and functional programming patterns
13
+ *
14
+ * **Performance Characteristics:**
15
+ * - get/has/delete: O(1) average case
16
+ * - set: O(1) average case
17
+ * - map/filter operations: O(n)
18
+ * - Iteration: O(n)
19
+ *
20
+ * @template K The type of the keys in the map. Must extend MapSetKeyType (string, number, boolean, etc.)
21
+ * @template V The type of the values in the map.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * // This is a type alias describing an interface, so it's not directly instantiated.
26
+ * // See IMap.create for examples of creating IMap instances that conform to this interface.
27
+ *
28
+ * // Example of how you might use a variable that implements this structure:
29
+ * declare const userMap: IMap<string, User>;
30
+ *
31
+ * // Immutable operations - original map is never modified
32
+ * const hasUser = userMap.has("alice"); // O(1)
33
+ * const user = userMap.get("alice").unwrapOr(defaultUser); // O(1)
34
+ * const newMap = userMap.set("bob", newUser); // O(1) - returns new IMap
35
+ * const updated = userMap.update("alice", u => ({ ...u, active: true })); // O(1)
36
+ *
37
+ * // Functional transformations
38
+ * const activeUsers = userMap.map((user, id) => ({ ...user, lastSeen: Date.now() })); // O(n)
39
+ * ```
40
+ */
41
+ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
42
+ /** The number of elements in the map. */
43
+ size: SizeType.Arr;
44
+ /**
45
+ * Checks if a key exists in the map.
46
+ * Allows for wider literal types for keys during checking.
47
+ * @param key The key to check.
48
+ * @returns `true` if the key exists, `false` otherwise.
49
+ */
50
+ has: (key: K | (WidenLiteral<K> & {})) => boolean;
51
+ /**
52
+ * Retrieves the value associated with a key.
53
+ * @param key The key to retrieve.
54
+ * @returns The value associated with the key wrapped with Optional.some, or `Optional.none` if the key does not exist.
55
+ */
56
+ get: (key: K | (WidenLiteral<K> & {})) => Optional<V>;
57
+ /**
58
+ * Checks if all elements in the map satisfy a predicate.
59
+ * @param predicate A function to test each key-value pair.
60
+ * @returns `true` if all elements satisfy the predicate, `false` otherwise.
61
+ */
62
+ every: ((predicate: (value: V, key: K) => boolean) => boolean) &
63
+ /**
64
+ * Checks if all elements in the map satisfy a type predicate.
65
+ * Narrows the type of values in the map if the predicate returns true for all elements.
66
+ * @template W The narrowed type of the values.
67
+ * @param predicate A type predicate function.
68
+ * @returns `true` if all elements satisfy the predicate, `false` otherwise.
69
+ */
70
+ (<W extends V>(predicate: (value: V, key: K) => value is W) => this is IMap<K, W>);
71
+ /**
72
+ * Checks if at least one element in the map satisfies a predicate.
73
+ * @param predicate A function to test each key-value pair.
74
+ * @returns `true` if at least one element satisfies the predicate, `false` otherwise.
75
+ */
76
+ some: (predicate: (value: V, key: K) => boolean) => boolean;
77
+ /**
78
+ * Deletes a key-value pair from the map.
79
+ * @param key The key to delete.
80
+ * @returns A new IMap instance without the specified key.
81
+ */
82
+ delete: (key: K) => IMap<K, V>;
83
+ /**
84
+ * Sets a key-value pair in the map.
85
+ * @param key The key to set.
86
+ * @param value The value to associate with the key.
87
+ * @returns A new IMap instance with the specified key-value pair.
88
+ */
89
+ set: (key: K, value: V) => IMap<K, V>;
90
+ /**
91
+ * Updates the value associated with a key using an updater function.
92
+ * @param key The key whose value to update.
93
+ * @param updater A function that takes the current value and returns the new value.
94
+ * @returns A new IMap instance with the updated value.
95
+ */
96
+ update: (key: K, updater: (value: V) => V) => IMap<K, V>;
97
+ /**
98
+ * Applies a series of mutations to the map.
99
+ * @param actions An array of mutation actions (delete, set, or update).
100
+ * @returns A new IMap instance with all mutations applied.
101
+ */
102
+ withMutations: (actions: readonly Readonly<{
103
+ type: 'delete';
104
+ key: K;
105
+ } | {
106
+ type: 'set';
107
+ key: K;
108
+ value: V;
109
+ } | {
110
+ type: 'update';
111
+ key: K;
112
+ updater: (value: V) => V;
113
+ }>[]) => IMap<K, V>;
114
+ /**
115
+ * Maps the values of the map to new values.
116
+ * @template V2 The type of the new values.
117
+ * @param mapFn A function that maps a value and key to a new value.
118
+ * @returns A new IMap instance with mapped values.
119
+ */
120
+ map: <V2>(mapFn: (value: V, key: K) => V2) => IMap<K, V2>;
121
+ /**
122
+ * Maps the keys of the map to new keys.
123
+ * @template K2 The type of the new keys.
124
+ * @param mapFn A function that maps a key to a new key.
125
+ * @returns A new IMap instance with mapped keys and original values.
126
+ */
127
+ mapKeys: <K2 extends MapSetKeyType>(mapFn: (key: K) => K2) => IMap<K2, V>;
128
+ /**
129
+ * Maps the entries (key-value pairs) of the map to new entries.
130
+ * @template K2 The type of the new keys in the entries.
131
+ * @template V2 The type of the new values in the entries.
132
+ * @param mapFn A function that maps an entry to a new entry.
133
+ * @returns A new IMap instance with mapped entries.
134
+ */
135
+ mapEntries: <K2 extends MapSetKeyType, V2>(mapFn: (entry: readonly [K, V]) => readonly [K2, V2]) => IMap<K2, V2>;
136
+ /**
137
+ * Executes a callback function for each key-value pair in the map.
138
+ * @param callbackfn A function to execute for each element.
139
+ */
140
+ forEach: (callbackfn: (value: V, key: K) => void) => void;
141
+ /**
142
+ * Returns an iterator for the keys in the map.
143
+ * @returns An iterable iterator of keys.
144
+ */
145
+ keys: () => IterableIterator<K>;
146
+ /**
147
+ * Returns an iterator for the values in the map.
148
+ * @returns An iterable iterator of values.
149
+ */
150
+ values: () => IterableIterator<V>;
151
+ /**
152
+ * Returns an iterator for the entries (key-value pairs) in the map.
153
+ * @returns An iterable iterator of entries.
154
+ */
155
+ entries: () => IterableIterator<readonly [K, V]>;
156
+ /**
157
+ * Converts the keys of the map to an array.
158
+ * @returns A readonly array of keys.
159
+ */
160
+ toKeysArray: () => readonly K[];
161
+ /**
162
+ * Converts the values of the map to an array.
163
+ * @returns A readonly array of values.
164
+ */
165
+ toValuesArray: () => readonly V[];
166
+ /**
167
+ * Converts the entries (key-value pairs) of the map to an array.
168
+ * @returns A readonly array of entries.
169
+ */
170
+ toEntriesArray: () => readonly (readonly [K, V])[];
171
+ /**
172
+ * Converts the map to an array of entries (key-value pairs).
173
+ * Alias for `toEntriesArray`.
174
+ * @returns A readonly array of entries.
175
+ */
176
+ toArray: () => readonly (readonly [K, V])[];
177
+ /**
178
+ * Returns the underlying readonly JavaScript Map.
179
+ * @returns The raw ReadonlyMap instance.
180
+ */
181
+ toRawMap: () => ReadonlyMap<K, V>;
182
+ }>;
183
+ /**
184
+ * Represents an immutable map with high-performance operations and functional programming support.
185
+ *
186
+ * IMap is a persistent data structure that provides all the functionality of JavaScript's Map
187
+ * while maintaining immutability. All operations that would normally mutate the map instead
188
+ * return new IMap instances, making it safe for functional programming and concurrent access.
189
+ *
190
+ * **Key Features:**
191
+ * - **Immutable**: All mutation operations return new instances
192
+ * - **High Performance**: O(1) average-case for get/set/has/delete operations
193
+ * - **Type Safe**: Full TypeScript support with generic key/value types
194
+ * - **Iterable**: Implements standard JavaScript iteration protocols
195
+ * - **Functional**: Rich API for map, filter, reduce-style operations
196
+ *
197
+ * **When to Use:**
198
+ * - State management in functional applications
199
+ * - Caching with immutable guarantees
200
+ * - Data structures that need to be shared across components
201
+ * - When you need Map functionality but want immutability
202
+ *
203
+ * @template K The type of the keys in the map. Must extend MapSetKeyType.
204
+ * @template V The type of the values in the map.
205
+ *
206
+ * @example
207
+ * ```typescript
208
+ * // Create an immutable map with initial data
209
+ * let userPreferences = IMap.create<string, UserPreference>([
210
+ * ["theme", { value: "dark", lastModified: Date.now() }],
211
+ * ["language", { value: "en", lastModified: Date.now() }]
212
+ * ]);
213
+ *
214
+ * console.log(userPreferences.get("theme").unwrapOr(defaultPreference));
215
+ * console.log(userPreferences.size); // Output: 2
216
+ *
217
+ * // All operations return new instances - original is unchanged
218
+ * const updated = userPreferences
219
+ * .set("notifications", { value: true, lastModified: Date.now() })
220
+ * .update("theme", pref => ({ ...pref, value: "light" }));
221
+ *
222
+ * console.log(userPreferences.has("notifications")); // false (original unchanged)
223
+ * console.log(updated.has("notifications")); // true (new instance)
224
+ *
225
+ * // Efficient iteration and transformation
226
+ * for (const [key, preference] of updated) {
227
+ * console.log(`${key}: ${preference.value}`);
228
+ * }
229
+ *
230
+ * // Functional transformations
231
+ * const withTimestamps = updated.map((pref, key) => ({
232
+ * ...pref,
233
+ * accessedAt: Date.now()
234
+ * }));
235
+ *
236
+ * // Type-safe operations with narrowing
237
+ * const stringKeys = IMap.create<number | string, any>([[1, "a"], ["b", 2]]);
238
+ * const onlyStringKeys = stringKeys.mapKeys(key =>
239
+ * typeof key === "string" ? key : key.toString()
240
+ * );
241
+ * ```
242
+ */
243
+ export type IMap<K extends MapSetKeyType, V> = Iterable<readonly [K, V]> & IMapInterface<K, V>;
244
+ /**
245
+ * Provides utility functions for IMap.
246
+ */
247
+ export declare namespace IMap {
248
+ /**
249
+ * Creates a new IMap instance from an iterable of key-value pairs.
250
+ *
251
+ * This factory function accepts any iterable of [key, value] tuples, including arrays,
252
+ * JavaScript Maps, other IMaps, or custom iterables. The resulting IMap will contain
253
+ * all the entries from the input iterable.
254
+ *
255
+ * **Performance:** O(n) where n is the number of entries in the iterable.
256
+ *
257
+ * @template K The type of the keys. Must extend MapSetKeyType.
258
+ * @template V The type of the values.
259
+ * @param iterable An iterable of key-value pairs (e.g., Array, Map, IMap, etc.)
260
+ * @returns A new IMap instance containing all entries from the iterable.
261
+ *
262
+ * @example
263
+ * ```typescript
264
+ * // From array of tuples
265
+ * const userScores = IMap.create<string, number>([
266
+ * ["alice", 95],
267
+ * ["bob", 87],
268
+ * ["charlie", 92]
269
+ * ]);
270
+ * console.log(userScores.get("alice").unwrap()); // Output: 95
271
+ *
272
+ * // From JavaScript Map
273
+ * const jsMap = new Map([["config", { debug: true }], ["env", "production"]]);
274
+ * const config = IMap.create(jsMap);
275
+ * console.log(config.get("env").unwrap()); // Output: "production"
276
+ *
277
+ * // From another IMap (creates a copy)
278
+ * const originalMap = IMap.create<string, boolean>([["enabled", true]]);
279
+ * const copiedMap = IMap.create(originalMap);
280
+ * console.log(copiedMap.get("enabled").unwrap()); // Output: true
281
+ *
282
+ * // Empty map
283
+ * const emptyMap = IMap.create<string, number>([]);
284
+ * console.log(emptyMap.size); // Output: 0
285
+ *
286
+ * // From custom iterable
287
+ * function* generateEntries(): Generator<[string, number]> {
288
+ * for (let i = 0; i < 3; i++) {
289
+ * yield [`item${i}`, i * 10];
290
+ * }
291
+ * }
292
+ * const generatedMap = IMap.create(generateEntries());
293
+ * console.log(generatedMap.size); // Output: 3
294
+ * ```
295
+ */
296
+ const create: <K extends MapSetKeyType, V>(iterable: Iterable<readonly [K, V]>) => IMap<K, V>;
297
+ /**
298
+ * Checks if two IMap instances are structurally equal.
299
+ *
300
+ * Two IMaps are considered equal if they have the same size and contain exactly the same
301
+ * key-value pairs. The order of entries does not matter for equality comparison.
302
+ * Values are compared using JavaScript's `===` operator.
303
+ *
304
+ * **Performance:** O(n) where n is the size of the smaller map.
305
+ *
306
+ * @template K The type of the keys.
307
+ * @template V The type of the values.
308
+ * @param a The first IMap instance to compare.
309
+ * @param b The second IMap instance to compare.
310
+ * @returns `true` if the maps contain exactly the same key-value pairs, `false` otherwise.
311
+ *
312
+ * @example
313
+ * ```typescript
314
+ * // Basic equality comparison
315
+ * const preferences1 = IMap.create<string, boolean>([
316
+ * ["darkMode", true],
317
+ * ["notifications", false]
318
+ * ]);
319
+ * const preferences2 = IMap.create<string, boolean>([
320
+ * ["darkMode", true],
321
+ * ["notifications", false]
322
+ * ]);
323
+ * const preferences3 = IMap.create<string, boolean>([
324
+ * ["notifications", false],
325
+ * ["darkMode", true] // Order doesn't matter
326
+ * ]);
327
+ *
328
+ * console.log(IMap.equal(preferences1, preferences2)); // true
329
+ * console.log(IMap.equal(preferences1, preferences3)); // true (order doesn't matter)
330
+ *
331
+ * // Different values
332
+ * const preferences4 = IMap.create<string, boolean>([
333
+ * ["darkMode", false], // Different value
334
+ * ["notifications", false]
335
+ * ]);
336
+ * console.log(IMap.equal(preferences1, preferences4)); // false
337
+ *
338
+ * // Different keys
339
+ * const preferences5 = IMap.create<string, boolean>([
340
+ * ["darkMode", true],
341
+ * ["sounds", false] // Different key
342
+ * ]);
343
+ * console.log(IMap.equal(preferences1, preferences5)); // false
344
+ *
345
+ * // Empty maps
346
+ * const empty1 = IMap.create<string, number>([]);
347
+ * const empty2 = IMap.create<string, number>([]);
348
+ * console.log(IMap.equal(empty1, empty2)); // true
349
+ *
350
+ * // Note: For deep equality of object values, use a custom comparison
351
+ * const users1 = IMap.create<string, User>([["1", { name: "Alice" }]]);
352
+ * const users2 = IMap.create<string, User>([["1", { name: "Alice" }]]);
353
+ * console.log(IMap.equal(users1, users2)); // false (different object references)
354
+ * ```
355
+ */
356
+ const equal: <K extends MapSetKeyType, V>(a: IMap<K, V>, b: IMap<K, V>) => boolean;
357
+ }
358
+ export {};
359
+ //# sourceMappingURL=imap.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imap.d.mts","sourceRoot":"","sources":["../../src/collections/imap.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAU,MAAM,yBAAyB,CAAC;AAK3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,KAAK,aAAa,CAAC,CAAC,SAAS,aAAa,EAAE,CAAC,IAAI,QAAQ,CAAC;IAGxD,yCAAyC;IACzC,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC;IAEnB;;;;;OAKG;IACH,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC;IAElD;;;;OAIG;IACH,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC;IAItD;;;;OAIG;IACH,K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