@nicolastoulemont/std 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/adt/index.d.mts +2 -0
- package/dist/adt/index.mjs +3 -0
- package/dist/adt-DraJkmij.mjs +318 -0
- package/dist/adt-DraJkmij.mjs.map +1 -0
- package/dist/apply-fn.types-CXDoeA7D.d.mts +8 -0
- package/dist/apply-fn.types-CXDoeA7D.d.mts.map +1 -0
- package/dist/brand/index.d.mts +2 -0
- package/dist/brand/index.mjs +3 -0
- package/dist/brand-CTaxGuU9.mjs +165 -0
- package/dist/brand-CTaxGuU9.mjs.map +1 -0
- package/dist/data/index.d.mts +2 -0
- package/dist/data/index.mjs +3 -0
- package/dist/data-DgzWI4R_.mjs +244 -0
- package/dist/data-DgzWI4R_.mjs.map +1 -0
- package/dist/discriminator.types-DCkkrCj4.d.mts +7 -0
- package/dist/discriminator.types-DCkkrCj4.d.mts.map +1 -0
- package/dist/either/index.d.mts +2 -0
- package/dist/either/index.mjs +3 -0
- package/dist/either-CnOBUH7a.mjs +598 -0
- package/dist/either-CnOBUH7a.mjs.map +1 -0
- package/dist/equality/index.d.mts +86 -0
- package/dist/equality/index.d.mts.map +1 -0
- package/dist/equality/index.mjs +3 -0
- package/dist/equality-YMebYwm1.mjs +201 -0
- package/dist/equality-YMebYwm1.mjs.map +1 -0
- package/dist/err/index.d.mts +2 -0
- package/dist/err/index.mjs +3 -0
- package/dist/err-BqQApH9r.mjs +169 -0
- package/dist/err-BqQApH9r.mjs.map +1 -0
- package/dist/flow/index.d.mts +2 -0
- package/dist/flow/index.mjs +3 -0
- package/dist/flow-pRdnqmMY.mjs +21 -0
- package/dist/flow-pRdnqmMY.mjs.map +1 -0
- package/dist/gen/index.d.mts +3 -0
- package/dist/gen/index.mjs +3 -0
- package/dist/gen-YfMC9sDT.mjs +42 -0
- package/dist/gen-YfMC9sDT.mjs.map +1 -0
- package/dist/index-BCrD3pEs.d.mts +222 -0
- package/dist/index-BCrD3pEs.d.mts.map +1 -0
- package/dist/index-BR7takNf.d.mts +186 -0
- package/dist/index-BR7takNf.d.mts.map +1 -0
- package/dist/index-CcPnhWje.d.mts +72 -0
- package/dist/index-CcPnhWje.d.mts.map +1 -0
- package/dist/index-CtJ8Ks9X.d.mts +105 -0
- package/dist/index-CtJ8Ks9X.d.mts.map +1 -0
- package/dist/index-CvGTIg9L.d.mts +211 -0
- package/dist/index-CvGTIg9L.d.mts.map +1 -0
- package/dist/index-DPVT0yK4.d.mts +50 -0
- package/dist/index-DPVT0yK4.d.mts.map +1 -0
- package/dist/index-DgOAEEpu.d.mts +79 -0
- package/dist/index-DgOAEEpu.d.mts.map +1 -0
- package/dist/index-Dtq3kmln.d.mts +394 -0
- package/dist/index-Dtq3kmln.d.mts.map +1 -0
- package/dist/index-bLRqTe5I.d.mts +80 -0
- package/dist/index-bLRqTe5I.d.mts.map +1 -0
- package/dist/index-tkgTLCoq.d.mts +80 -0
- package/dist/index-tkgTLCoq.d.mts.map +1 -0
- package/dist/index-wTrnFgYg.d.mts +57 -0
- package/dist/index-wTrnFgYg.d.mts.map +1 -0
- package/dist/index-yyBTq8Ys.d.mts +79 -0
- package/dist/index-yyBTq8Ys.d.mts.map +1 -0
- package/dist/index.d.mts +135 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +41 -0
- package/dist/index.mjs.map +1 -0
- package/dist/is-promise-BEl3eGZg.mjs +11 -0
- package/dist/is-promise-BEl3eGZg.mjs.map +1 -0
- package/dist/option/index.d.mts +3 -0
- package/dist/option/index.mjs +3 -0
- package/dist/option-CKHDOVea.mjs +410 -0
- package/dist/option-CKHDOVea.mjs.map +1 -0
- package/dist/option.types-D6TYG_i3.d.mts +89 -0
- package/dist/option.types-D6TYG_i3.d.mts.map +1 -0
- package/dist/pipe/index.d.mts +2 -0
- package/dist/pipe/index.mjs +3 -0
- package/dist/pipe-GYxZNkPB.mjs +10 -0
- package/dist/pipe-GYxZNkPB.mjs.map +1 -0
- package/dist/predicate/index.d.mts +2 -0
- package/dist/predicate/index.mjs +3 -0
- package/dist/predicate-B6-EdVgW.mjs +293 -0
- package/dist/predicate-B6-EdVgW.mjs.map +1 -0
- package/dist/result/index.d.mts +3 -0
- package/dist/result/index.mjs +3 -0
- package/dist/result-C5tPWR60.mjs +422 -0
- package/dist/result-C5tPWR60.mjs.map +1 -0
- package/dist/result-D7XJ96pv.mjs +1 -0
- package/dist/result.types-Ce7AEOzj.d.mts +156 -0
- package/dist/result.types-Ce7AEOzj.d.mts.map +1 -0
- package/dist/run/index.d.mts +2 -0
- package/dist/run/index.mjs +3 -0
- package/dist/run-DpXkImo9.mjs +10 -0
- package/dist/run-DpXkImo9.mjs.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { a as deepEquals, i as createHashMethod, o as deepHash, r as createEqualsMethod } from "./equality-YMebYwm1.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/data/data.tagged.ts
|
|
4
|
+
/**
|
|
5
|
+
* Create a tagged value constructor without schema validation.
|
|
6
|
+
*
|
|
7
|
+
* Unlike record(), this creates values directly without validation.
|
|
8
|
+
* Values are frozen and have structural equality via equals() and hash() methods.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The data shape type (excluding __typename)
|
|
11
|
+
* @param typename - The __typename discriminator value
|
|
12
|
+
* @returns A constructor function with is(), equals(), and hash() methods
|
|
13
|
+
*
|
|
14
|
+
* @see {@link record} for validated records with schema support
|
|
15
|
+
* @see {@link struct} for untagged value objects
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const Person = tagged<{ name: string; age: number }>("Person")
|
|
20
|
+
*
|
|
21
|
+
* const alice = Person({ name: "Alice", age: 30 })
|
|
22
|
+
* // => { __typename: "Person", name: "Alice", age: 30 }
|
|
23
|
+
*
|
|
24
|
+
* Person.equals(alice, Person({ name: "Alice", age: 30 })) // true
|
|
25
|
+
* Person.is(alice) // true
|
|
26
|
+
*
|
|
27
|
+
* // Type guard usage
|
|
28
|
+
* if (Person.is(unknownValue)) {
|
|
29
|
+
* console.log(unknownValue.name) // TypeScript knows it's a Person
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* // Values are frozen (immutable)
|
|
33
|
+
* alice.name = "Bob" // TypeError
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
function tagged(typename) {
|
|
37
|
+
const constructor = (input) => {
|
|
38
|
+
return Object.freeze({
|
|
39
|
+
...input,
|
|
40
|
+
__typename: typename
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
constructor.is = (value) => {
|
|
44
|
+
return typeof value === "object" && value !== null && "__typename" in value && value.__typename === typename;
|
|
45
|
+
};
|
|
46
|
+
constructor.equals = createEqualsMethod(typename);
|
|
47
|
+
constructor.hash = createHashMethod(typename);
|
|
48
|
+
constructor.__typename = typename;
|
|
49
|
+
return constructor;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/data/data.struct.ts
|
|
54
|
+
/**
|
|
55
|
+
* Create a frozen value object with structural equality.
|
|
56
|
+
*
|
|
57
|
+
* Unlike tagged(), struct() does not add a __typename discriminator.
|
|
58
|
+
* Use this for simple value objects that don't need discrimination.
|
|
59
|
+
*
|
|
60
|
+
* The returned object is frozen (immutable) and has non-enumerable
|
|
61
|
+
* equals() and hash() methods for structural comparison.
|
|
62
|
+
*
|
|
63
|
+
* @template T - The object shape type
|
|
64
|
+
* @param input - The object to wrap
|
|
65
|
+
* @returns A frozen object with equals() and hash() methods
|
|
66
|
+
*
|
|
67
|
+
* @see {@link tagged} for discriminated value objects with __typename
|
|
68
|
+
* @see {@link array} for array value types
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const point = struct({ x: 10, y: 20 })
|
|
73
|
+
* const point2 = struct({ x: 10, y: 20 })
|
|
74
|
+
*
|
|
75
|
+
* point.equals(point2) // true
|
|
76
|
+
* point.hash() // number
|
|
77
|
+
*
|
|
78
|
+
* // Object is frozen
|
|
79
|
+
* point.x = 5 // TypeError
|
|
80
|
+
*
|
|
81
|
+
* // equals/hash are non-enumerable
|
|
82
|
+
* Object.keys(point) // ["x", "y"]
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
function struct(input) {
|
|
86
|
+
const value = { ...input };
|
|
87
|
+
Object.defineProperty(value, "equals", {
|
|
88
|
+
value: (other) => deepEquals(value, other),
|
|
89
|
+
enumerable: false,
|
|
90
|
+
writable: false,
|
|
91
|
+
configurable: false
|
|
92
|
+
});
|
|
93
|
+
Object.defineProperty(value, "hash", {
|
|
94
|
+
value: () => deepHash(value),
|
|
95
|
+
enumerable: false,
|
|
96
|
+
writable: false,
|
|
97
|
+
configurable: false
|
|
98
|
+
});
|
|
99
|
+
return Object.freeze(value);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/data/data.tuple.ts
|
|
104
|
+
/**
|
|
105
|
+
* Create a tuple with structural equality.
|
|
106
|
+
*
|
|
107
|
+
* The returned tuple is frozen (immutable) and has non-enumerable
|
|
108
|
+
* equals() and hash() methods for structural comparison.
|
|
109
|
+
*
|
|
110
|
+
* @template T - The tuple type as a readonly array of element types
|
|
111
|
+
* @param args - The tuple elements
|
|
112
|
+
* @returns A frozen tuple-like array with equals() and hash() methods
|
|
113
|
+
*
|
|
114
|
+
* @see {@link array} for variable-length arrays with equality
|
|
115
|
+
* @see {@link struct} for object value types
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* const t1 = tuple(1, "hello", true)
|
|
120
|
+
* const t2 = tuple(1, "hello", true)
|
|
121
|
+
*
|
|
122
|
+
* t1.equals(t2) // true
|
|
123
|
+
* t1.hash() // number
|
|
124
|
+
*
|
|
125
|
+
* // Access elements (typed)
|
|
126
|
+
* t1[0] // number
|
|
127
|
+
* t1[1] // string
|
|
128
|
+
* t1[2] // boolean
|
|
129
|
+
*
|
|
130
|
+
* // Tuple is frozen
|
|
131
|
+
* t1[0] = 5 // TypeError
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
function tuple(...args) {
|
|
135
|
+
const value = [...args];
|
|
136
|
+
Object.defineProperty(value, "equals", {
|
|
137
|
+
value: (other) => deepEquals(value, other),
|
|
138
|
+
enumerable: false,
|
|
139
|
+
writable: false,
|
|
140
|
+
configurable: false
|
|
141
|
+
});
|
|
142
|
+
Object.defineProperty(value, "hash", {
|
|
143
|
+
value: () => deepHash(value),
|
|
144
|
+
enumerable: false,
|
|
145
|
+
writable: false,
|
|
146
|
+
configurable: false
|
|
147
|
+
});
|
|
148
|
+
return Object.freeze(value);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/data/data.array.ts
|
|
153
|
+
/**
|
|
154
|
+
* Create an array with structural equality.
|
|
155
|
+
*
|
|
156
|
+
* The returned array is frozen (immutable) and has non-enumerable
|
|
157
|
+
* equals() and hash() methods for structural comparison.
|
|
158
|
+
*
|
|
159
|
+
* The map() and filter() methods are overridden to return ArrayValue,
|
|
160
|
+
* enabling method chaining with preserved equality semantics.
|
|
161
|
+
*
|
|
162
|
+
* @template T - The element type of the array
|
|
163
|
+
* @param items - The array elements
|
|
164
|
+
* @returns A frozen array with equals(), hash(), map(), and filter()
|
|
165
|
+
*
|
|
166
|
+
* @see {@link tuple} for fixed-length typed tuples
|
|
167
|
+
* @see {@link struct} for object value types
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* const arr1 = array([1, 2, 3])
|
|
172
|
+
* const arr2 = array([1, 2, 3])
|
|
173
|
+
*
|
|
174
|
+
* arr1.equals(arr2) // true
|
|
175
|
+
* arr1.hash() // number
|
|
176
|
+
*
|
|
177
|
+
* // Chainable operations return ArrayValue
|
|
178
|
+
* arr1.map(x => x * 2) // ArrayValue<number>
|
|
179
|
+
* arr1.filter(x => x > 1) // ArrayValue<number>
|
|
180
|
+
*
|
|
181
|
+
* // Chained equality check
|
|
182
|
+
* arr1.map(x => x * 2).equals(array([2, 4, 6])) // true
|
|
183
|
+
*
|
|
184
|
+
* // Array is frozen
|
|
185
|
+
* arr1[0] = 5 // TypeError
|
|
186
|
+
* arr1.push(4) // TypeError
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
function array(items) {
|
|
190
|
+
const value = [...items];
|
|
191
|
+
Object.defineProperty(value, "equals", {
|
|
192
|
+
value: (other) => deepEquals(value, other),
|
|
193
|
+
enumerable: false,
|
|
194
|
+
writable: false,
|
|
195
|
+
configurable: false
|
|
196
|
+
});
|
|
197
|
+
Object.defineProperty(value, "hash", {
|
|
198
|
+
value: () => deepHash(value),
|
|
199
|
+
enumerable: false,
|
|
200
|
+
writable: false,
|
|
201
|
+
configurable: false
|
|
202
|
+
});
|
|
203
|
+
const originalMap = value.map.bind(value);
|
|
204
|
+
Object.defineProperty(value, "map", {
|
|
205
|
+
value: (fn) => {
|
|
206
|
+
return array(originalMap(fn));
|
|
207
|
+
},
|
|
208
|
+
enumerable: false,
|
|
209
|
+
writable: false,
|
|
210
|
+
configurable: false
|
|
211
|
+
});
|
|
212
|
+
const originalFilter = value.filter.bind(value);
|
|
213
|
+
Object.defineProperty(value, "filter", {
|
|
214
|
+
value: (fn) => {
|
|
215
|
+
return array(originalFilter(fn));
|
|
216
|
+
},
|
|
217
|
+
enumerable: false,
|
|
218
|
+
writable: false,
|
|
219
|
+
configurable: false
|
|
220
|
+
});
|
|
221
|
+
const originalSlice = value.slice.bind(value);
|
|
222
|
+
Object.defineProperty(value, "slice", {
|
|
223
|
+
value: (start, end) => {
|
|
224
|
+
return array(originalSlice(start, end));
|
|
225
|
+
},
|
|
226
|
+
enumerable: false,
|
|
227
|
+
writable: false,
|
|
228
|
+
configurable: false
|
|
229
|
+
});
|
|
230
|
+
const originalConcat = value.concat.bind(value);
|
|
231
|
+
Object.defineProperty(value, "concat", {
|
|
232
|
+
value: (...args) => {
|
|
233
|
+
return array(originalConcat(...args));
|
|
234
|
+
},
|
|
235
|
+
enumerable: false,
|
|
236
|
+
writable: false,
|
|
237
|
+
configurable: false
|
|
238
|
+
});
|
|
239
|
+
return Object.freeze(value);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
//#endregion
|
|
243
|
+
export { tagged as i, tuple as n, struct as r, array as t };
|
|
244
|
+
//# sourceMappingURL=data-DgzWI4R_.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-DgzWI4R_.mjs","names":[],"sources":["../src/data/data.tagged.ts","../src/data/data.struct.ts","../src/data/data.tuple.ts","../src/data/data.array.ts"],"sourcesContent":["import { createEqualsMethod, createHashMethod } from \"../equality/equality\"\nimport type { Discriminator } from \"../shared/discriminator.types\"\nimport type { TaggedConstructor, TaggedValue } from \"./data.types\"\n\n/**\n * Create a tagged value constructor without schema validation.\n *\n * Unlike record(), this creates values directly without validation.\n * Values are frozen and have structural equality via equals() and hash() methods.\n *\n * @template T - The data shape type (excluding __typename)\n * @param typename - The __typename discriminator value\n * @returns A constructor function with is(), equals(), and hash() methods\n *\n * @see {@link record} for validated records with schema support\n * @see {@link struct} for untagged value objects\n *\n * @example\n * ```ts\n * const Person = tagged<{ name: string; age: number }>(\"Person\")\n *\n * const alice = Person({ name: \"Alice\", age: 30 })\n * // => { __typename: \"Person\", name: \"Alice\", age: 30 }\n *\n * Person.equals(alice, Person({ name: \"Alice\", age: 30 })) // true\n * Person.is(alice) // true\n *\n * // Type guard usage\n * if (Person.is(unknownValue)) {\n * console.log(unknownValue.name) // TypeScript knows it's a Person\n * }\n *\n * // Values are frozen (immutable)\n * alice.name = \"Bob\" // TypeError\n * ```\n */\nexport function tagged<T extends Record<string, unknown>>(typename: string): TaggedConstructor<typeof typename, T> {\n type Output = TaggedValue<typeof typename, T>\n\n // Constructor function\n const constructor = (input: T): Output => {\n return Object.freeze({ ...input, __typename: typename }) as Output\n }\n\n // Type guard\n constructor.is = (value: unknown): value is Output => {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"__typename\" in value &&\n // oxlint-disable-next-line no-unsafe-type-assertion -- Already checked with 'in' operator\n (value as Discriminator).__typename === typename\n )\n }\n\n // Equality (static method on constructor)\n constructor.equals = createEqualsMethod<typeof typename, T>(typename)\n\n // Hashing (static method on constructor)\n constructor.hash = createHashMethod<typeof typename, T>(typename)\n\n // Store typename for reflection\n constructor.__typename = typename\n\n return constructor as TaggedConstructor<typeof typename, T>\n}\n","import { deepEquals, deepHash } from \"../equality/equality\"\nimport type { StructValue } from \"./data.types\"\n\n/**\n * Create a frozen value object with structural equality.\n *\n * Unlike tagged(), struct() does not add a __typename discriminator.\n * Use this for simple value objects that don't need discrimination.\n *\n * The returned object is frozen (immutable) and has non-enumerable\n * equals() and hash() methods for structural comparison.\n *\n * @template T - The object shape type\n * @param input - The object to wrap\n * @returns A frozen object with equals() and hash() methods\n *\n * @see {@link tagged} for discriminated value objects with __typename\n * @see {@link array} for array value types\n *\n * @example\n * ```ts\n * const point = struct({ x: 10, y: 20 })\n * const point2 = struct({ x: 10, y: 20 })\n *\n * point.equals(point2) // true\n * point.hash() // number\n *\n * // Object is frozen\n * point.x = 5 // TypeError\n *\n * // equals/hash are non-enumerable\n * Object.keys(point) // [\"x\", \"y\"]\n * ```\n */\nexport function struct<T extends Record<string, unknown>>(input: T): StructValue<T> {\n const value = { ...input }\n\n // Add equals method (non-enumerable)\n Object.defineProperty(value, \"equals\", {\n value: (other: T) => deepEquals(value, other),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Add hash method (non-enumerable)\n Object.defineProperty(value, \"hash\", {\n value: () => deepHash(value),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for generic struct return type\n return Object.freeze(value) as StructValue<T>\n}\n","import { deepEquals, deepHash } from \"../equality/equality\"\nimport type { TupleValue } from \"./data.types\"\n\n/**\n * Create a tuple with structural equality.\n *\n * The returned tuple is frozen (immutable) and has non-enumerable\n * equals() and hash() methods for structural comparison.\n *\n * @template T - The tuple type as a readonly array of element types\n * @param args - The tuple elements\n * @returns A frozen tuple-like array with equals() and hash() methods\n *\n * @see {@link array} for variable-length arrays with equality\n * @see {@link struct} for object value types\n *\n * @example\n * ```ts\n * const t1 = tuple(1, \"hello\", true)\n * const t2 = tuple(1, \"hello\", true)\n *\n * t1.equals(t2) // true\n * t1.hash() // number\n *\n * // Access elements (typed)\n * t1[0] // number\n * t1[1] // string\n * t1[2] // boolean\n *\n * // Tuple is frozen\n * t1[0] = 5 // TypeError\n * ```\n */\nexport function tuple<T extends readonly unknown[]>(...args: T): TupleValue<T> {\n const value = [...args]\n\n // Add equals method (non-enumerable)\n Object.defineProperty(value, \"equals\", {\n value: (other: readonly unknown[]) => deepEquals(value, other),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Add hash method (non-enumerable)\n Object.defineProperty(value, \"hash\", {\n value: () => deepHash(value),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for generic tuple return type\n return Object.freeze(value) as unknown as TupleValue<T>\n}\n","import { deepEquals, deepHash } from \"../equality/equality\"\nimport type { ArrayValue } from \"./data.types\"\n\n/**\n * Create an array with structural equality.\n *\n * The returned array is frozen (immutable) and has non-enumerable\n * equals() and hash() methods for structural comparison.\n *\n * The map() and filter() methods are overridden to return ArrayValue,\n * enabling method chaining with preserved equality semantics.\n *\n * @template T - The element type of the array\n * @param items - The array elements\n * @returns A frozen array with equals(), hash(), map(), and filter()\n *\n * @see {@link tuple} for fixed-length typed tuples\n * @see {@link struct} for object value types\n *\n * @example\n * ```ts\n * const arr1 = array([1, 2, 3])\n * const arr2 = array([1, 2, 3])\n *\n * arr1.equals(arr2) // true\n * arr1.hash() // number\n *\n * // Chainable operations return ArrayValue\n * arr1.map(x => x * 2) // ArrayValue<number>\n * arr1.filter(x => x > 1) // ArrayValue<number>\n *\n * // Chained equality check\n * arr1.map(x => x * 2).equals(array([2, 4, 6])) // true\n *\n * // Array is frozen\n * arr1[0] = 5 // TypeError\n * arr1.push(4) // TypeError\n * ```\n */\nexport function array<T>(items: readonly T[]): ArrayValue<T> {\n const value = [...items]\n\n // Add equals method (non-enumerable)\n Object.defineProperty(value, \"equals\", {\n value: (other: readonly T[]) => deepEquals(value, other),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Add hash method (non-enumerable)\n Object.defineProperty(value, \"hash\", {\n value: () => deepHash(value),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Override map to return ArrayValue\n const originalMap = value.map.bind(value)\n Object.defineProperty(value, \"map\", {\n value: <U>(fn: (item: T, index: number, arr: readonly T[]) => U): ArrayValue<U> => {\n return array(originalMap(fn))\n },\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Override filter to return ArrayValue\n const originalFilter = value.filter.bind(value)\n Object.defineProperty(value, \"filter\", {\n value: (fn: (item: T, index: number, arr: readonly T[]) => boolean): ArrayValue<T> => {\n return array(originalFilter(fn))\n },\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Override slice to return ArrayValue\n const originalSlice = value.slice.bind(value)\n Object.defineProperty(value, \"slice\", {\n value: (start?: number, end?: number): ArrayValue<T> => {\n return array(originalSlice(start, end))\n },\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Override concat to return ArrayValue\n const originalConcat = value.concat.bind(value)\n Object.defineProperty(value, \"concat\", {\n value: (...args: readonly (T | readonly T[])[]): ArrayValue<T> => {\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for concat argument spread\n return array(originalConcat(...(args as T[][])))\n },\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for generic array return type\n return Object.freeze(value) as unknown as ArrayValue<T>\n}\n"],"mappings":";;;;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