effect 3.2.3 → 3.2.4
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/dist/cjs/Array.js +777 -17
- package/dist/cjs/Array.js.map +1 -1
- package/dist/cjs/internal/pool.js +2 -2
- package/dist/cjs/internal/pool.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Array.d.ts +776 -16
- package/dist/dts/Array.d.ts.map +1 -1
- package/dist/esm/Array.js +777 -17
- package/dist/esm/Array.js.map +1 -1
- package/dist/esm/internal/pool.js +2 -2
- package/dist/esm/internal/pool.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Array.ts +777 -17
- package/src/internal/pool.ts +9 -6
- package/src/internal/version.ts +1 -1
package/dist/dts/Array.d.ts
CHANGED
|
@@ -32,6 +32,12 @@ export type NonEmptyArray<A> = [A, ...Array<A>];
|
|
|
32
32
|
/**
|
|
33
33
|
* Builds a `NonEmptyArray` from an non-empty collection of elements.
|
|
34
34
|
*
|
|
35
|
+
* @example
|
|
36
|
+
* import { Array } from "effect"
|
|
37
|
+
*
|
|
38
|
+
* const result = Array.make(1, 2, 3)
|
|
39
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
40
|
+
*
|
|
35
41
|
* @category constructors
|
|
36
42
|
* @since 2.0.0
|
|
37
43
|
*/
|
|
@@ -39,6 +45,12 @@ export declare const make: <Elements extends [any, ...any[]]>(...elements: Eleme
|
|
|
39
45
|
/**
|
|
40
46
|
* Creates a new `Array` of the specified length.
|
|
41
47
|
*
|
|
48
|
+
* @example
|
|
49
|
+
* import { Array } from "effect"
|
|
50
|
+
*
|
|
51
|
+
* const result = Array.allocate<number>(3)
|
|
52
|
+
* assert.deepStrictEqual(result.length, 3)
|
|
53
|
+
*
|
|
42
54
|
* @category constructors
|
|
43
55
|
* @since 2.0.0
|
|
44
56
|
*/
|
|
@@ -75,9 +87,9 @@ export declare const range: (start: number, end: number) => [number, ...number[]
|
|
|
75
87
|
* **Note**. `n` is normalized to an integer >= 1.
|
|
76
88
|
*
|
|
77
89
|
* @example
|
|
78
|
-
* import {
|
|
90
|
+
* import { Array } from "effect"
|
|
79
91
|
*
|
|
80
|
-
* assert.deepStrictEqual(replicate("a", 3), ["a", "a", "a"])
|
|
92
|
+
* assert.deepStrictEqual(Array.replicate("a", 3), ["a", "a", "a"])
|
|
81
93
|
*
|
|
82
94
|
* @category constructors
|
|
83
95
|
* @since 2.0.0
|
|
@@ -88,6 +100,15 @@ export declare const replicate: {
|
|
|
88
100
|
};
|
|
89
101
|
/**
|
|
90
102
|
* Creates a new `Array` from an iterable collection of values.
|
|
103
|
+
* If the input is already an array, it returns the input as-is.
|
|
104
|
+
* Otherwise, it converts the iterable collection to an array.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* import { Array } from "effect"
|
|
108
|
+
*
|
|
109
|
+
* const set = new Set([1, 2, 3])
|
|
110
|
+
* const result = Array.fromIterable(set)
|
|
111
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
91
112
|
*
|
|
92
113
|
* @category constructors
|
|
93
114
|
* @since 2.0.0
|
|
@@ -99,21 +120,41 @@ export declare const fromIterable: <A>(collection: Iterable<A>) => Array<A>;
|
|
|
99
120
|
* @param self - The record to transform.
|
|
100
121
|
*
|
|
101
122
|
* @example
|
|
102
|
-
* import {
|
|
123
|
+
* import { Array } from "effect"
|
|
103
124
|
*
|
|
104
125
|
* const x = { a: 1, b: 2, c: 3 }
|
|
105
|
-
* assert.deepStrictEqual(fromRecord(x), [["a", 1], ["b", 2], ["c", 3]])
|
|
126
|
+
* assert.deepStrictEqual(Array.fromRecord(x), [["a", 1], ["b", 2], ["c", 3]])
|
|
106
127
|
*
|
|
107
128
|
* @category conversions
|
|
108
129
|
* @since 2.0.0
|
|
109
130
|
*/
|
|
110
131
|
export declare const fromRecord: <K extends string, A>(self: Readonly<Record<K, A>>) => Array<[K, A]>;
|
|
111
132
|
/**
|
|
133
|
+
* Converts an `Option` to an array.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* import { Array, Option } from "effect"
|
|
137
|
+
*
|
|
138
|
+
* assert.deepStrictEqual(Array.fromOption(Option.some(1)), [1])
|
|
139
|
+
* assert.deepStrictEqual(Array.fromOption(Option.none()), [])
|
|
140
|
+
*
|
|
112
141
|
* @category conversions
|
|
113
142
|
* @since 2.0.0
|
|
114
143
|
*/
|
|
115
144
|
export declare const fromOption: <A>(self: Option<A>) => Array<A>;
|
|
116
145
|
/**
|
|
146
|
+
* Matches the elements of an array, applying functions to cases of empty and non-empty arrays.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* import { Array } from "effect"
|
|
150
|
+
*
|
|
151
|
+
* const match = Array.match({
|
|
152
|
+
* onEmpty: () => "empty",
|
|
153
|
+
* onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`
|
|
154
|
+
* })
|
|
155
|
+
* assert.deepStrictEqual(match([]), "empty")
|
|
156
|
+
* assert.deepStrictEqual(match([1, 2, 3]), "head: 1, tail: 2")
|
|
157
|
+
*
|
|
117
158
|
* @category pattern matching
|
|
118
159
|
* @since 2.0.0
|
|
119
160
|
*/
|
|
@@ -128,6 +169,18 @@ export declare const match: {
|
|
|
128
169
|
}): B | C;
|
|
129
170
|
};
|
|
130
171
|
/**
|
|
172
|
+
* Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* import { Array } from "effect"
|
|
176
|
+
*
|
|
177
|
+
* const matchLeft = Array.matchLeft({
|
|
178
|
+
* onEmpty: () => "empty",
|
|
179
|
+
* onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`
|
|
180
|
+
* })
|
|
181
|
+
* assert.deepStrictEqual(matchLeft([]), "empty")
|
|
182
|
+
* assert.deepStrictEqual(matchLeft([1, 2, 3]), "head: 1, tail: 2")
|
|
183
|
+
*
|
|
131
184
|
* @category pattern matching
|
|
132
185
|
* @since 2.0.0
|
|
133
186
|
*/
|
|
@@ -142,6 +195,18 @@ export declare const matchLeft: {
|
|
|
142
195
|
}): B | C;
|
|
143
196
|
};
|
|
144
197
|
/**
|
|
198
|
+
* Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* import { Array } from "effect"
|
|
202
|
+
*
|
|
203
|
+
* const matchRight = Array.matchRight({
|
|
204
|
+
* onEmpty: () => "empty",
|
|
205
|
+
* onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`
|
|
206
|
+
* })
|
|
207
|
+
* assert.deepStrictEqual(matchRight([]), "empty")
|
|
208
|
+
* assert.deepStrictEqual(matchRight([1, 2, 3]), "init: 2, last: 3")
|
|
209
|
+
*
|
|
145
210
|
* @category pattern matching
|
|
146
211
|
* @since 2.0.0
|
|
147
212
|
*/
|
|
@@ -158,6 +223,13 @@ export declare const matchRight: {
|
|
|
158
223
|
/**
|
|
159
224
|
* Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.
|
|
160
225
|
*
|
|
226
|
+
* @example
|
|
227
|
+
* import { Array } from "effect"
|
|
228
|
+
*
|
|
229
|
+
* const original = [2, 3, 4];
|
|
230
|
+
* const result = Array.prepend(original, 1);
|
|
231
|
+
* assert.deepStrictEqual(result, [1, 2, 3, 4]);
|
|
232
|
+
*
|
|
161
233
|
* @category concatenating
|
|
162
234
|
* @since 2.0.0
|
|
163
235
|
*/
|
|
@@ -172,10 +244,10 @@ export declare const prepend: {
|
|
|
172
244
|
* @example
|
|
173
245
|
* import { Array } from "effect"
|
|
174
246
|
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* )
|
|
247
|
+
* const prefix = [0, 1];
|
|
248
|
+
* const array = [2, 3];
|
|
249
|
+
* const result = Array.prependAll(array, prefix);
|
|
250
|
+
* assert.deepStrictEqual(result, [0, 1, 2, 3]);
|
|
179
251
|
*
|
|
180
252
|
* @category concatenating
|
|
181
253
|
* @since 2.0.0
|
|
@@ -189,6 +261,13 @@ export declare const prependAll: {
|
|
|
189
261
|
/**
|
|
190
262
|
* Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.
|
|
191
263
|
*
|
|
264
|
+
* @example
|
|
265
|
+
* import { Array } from "effect"
|
|
266
|
+
*
|
|
267
|
+
* const original = [1, 2, 3];
|
|
268
|
+
* const result = Array.append(original, 4);
|
|
269
|
+
* assert.deepStrictEqual(result, [1, 2, 3, 4]);
|
|
270
|
+
*
|
|
192
271
|
* @category concatenating
|
|
193
272
|
* @since 2.0.0
|
|
194
273
|
*/
|
|
@@ -210,7 +289,22 @@ export declare const appendAll: {
|
|
|
210
289
|
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>;
|
|
211
290
|
};
|
|
212
291
|
/**
|
|
213
|
-
*
|
|
292
|
+
* Accumulates values from an `Iterable` starting from the left, storing
|
|
293
|
+
* each intermediate result in an array. Useful for tracking the progression of
|
|
294
|
+
* a value through a series of transformations.
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* import { Array } from "effect";
|
|
298
|
+
*
|
|
299
|
+
* const numbers = [1, 2, 3, 4]
|
|
300
|
+
* const result = Array.scan(numbers, 0, (acc, value) => acc + value)
|
|
301
|
+
* assert.deepStrictEqual(result, [0, 1, 3, 6, 10])
|
|
302
|
+
*
|
|
303
|
+
* // Explanation:
|
|
304
|
+
* // This function starts with the initial value (0 in this case)
|
|
305
|
+
* // and adds each element of the array to this accumulator one by one,
|
|
306
|
+
* // keeping track of the cumulative sum after each addition.
|
|
307
|
+
* // Each of these sums is captured in the resulting array.
|
|
214
308
|
*
|
|
215
309
|
* @category folding
|
|
216
310
|
* @since 2.0.0
|
|
@@ -220,7 +314,16 @@ export declare const scan: {
|
|
|
220
314
|
<A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B>;
|
|
221
315
|
};
|
|
222
316
|
/**
|
|
223
|
-
*
|
|
317
|
+
* Accumulates values from an `Iterable` starting from the right, storing
|
|
318
|
+
* each intermediate result in an array. Useful for tracking the progression of
|
|
319
|
+
* a value through a series of transformations.
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* import { Array } from "effect";
|
|
323
|
+
*
|
|
324
|
+
* const numbers = [1, 2, 3, 4]
|
|
325
|
+
* const result = Array.scanRight(numbers, 0, (acc, value) => acc + value)
|
|
326
|
+
* assert.deepStrictEqual(result, [10, 9, 7, 4, 0])
|
|
224
327
|
*
|
|
225
328
|
* @category folding
|
|
226
329
|
* @since 2.0.0
|
|
@@ -341,6 +444,12 @@ export declare const unsafeGet: {
|
|
|
341
444
|
/**
|
|
342
445
|
* Return a tuple containing the first element, and a new `Array` of the remaining elements, if any.
|
|
343
446
|
*
|
|
447
|
+
* @example
|
|
448
|
+
* import { Array } from "effect";
|
|
449
|
+
*
|
|
450
|
+
* const result = Array.unprepend([1, 2, 3, 4])
|
|
451
|
+
* assert.deepStrictEqual(result, [1, [2, 3, 4]])
|
|
452
|
+
*
|
|
344
453
|
* @category splitting
|
|
345
454
|
* @since 2.0.0
|
|
346
455
|
*/
|
|
@@ -348,6 +457,12 @@ export declare const unprepend: <A>(self: readonly [A, ...A[]]) => [firstElement
|
|
|
348
457
|
/**
|
|
349
458
|
* Return a tuple containing a copy of the `NonEmptyReadonlyArray` without its last element, and that last element.
|
|
350
459
|
*
|
|
460
|
+
* @example
|
|
461
|
+
* import { Array } from "effect";
|
|
462
|
+
*
|
|
463
|
+
* const result = Array.unappend([1, 2, 3, 4])
|
|
464
|
+
* assert.deepStrictEqual(result, [[1, 2, 3], 4])
|
|
465
|
+
*
|
|
351
466
|
* @category splitting
|
|
352
467
|
* @since 2.0.0
|
|
353
468
|
*/
|
|
@@ -360,6 +475,14 @@ export declare const unappend: <A>(self: readonly [A, ...A[]]) => [arrayWithoutL
|
|
|
360
475
|
*/
|
|
361
476
|
export declare const head: <A>(self: ReadonlyArray<A>) => Option<A>;
|
|
362
477
|
/**
|
|
478
|
+
* Get the first element of a non empty array.
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* import { Array } from "effect"
|
|
482
|
+
*
|
|
483
|
+
* const result = Array.headNonEmpty([1, 2, 3, 4])
|
|
484
|
+
* assert.deepStrictEqual(result, 1)
|
|
485
|
+
*
|
|
363
486
|
* @category getters
|
|
364
487
|
* @since 2.0.0
|
|
365
488
|
*/
|
|
@@ -372,6 +495,14 @@ export declare const headNonEmpty: <A>(self: NonEmptyReadonlyArray<A>) => A;
|
|
|
372
495
|
*/
|
|
373
496
|
export declare const last: <A>(self: ReadonlyArray<A>) => Option<A>;
|
|
374
497
|
/**
|
|
498
|
+
* Get the last element of a non empty array.
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
* import { Array } from "effect"
|
|
502
|
+
*
|
|
503
|
+
* const result = Array.lastNonEmpty([1, 2, 3, 4])
|
|
504
|
+
* assert.deepStrictEqual(result, 4)
|
|
505
|
+
*
|
|
375
506
|
* @category getters
|
|
376
507
|
* @since 2.0.0
|
|
377
508
|
*/
|
|
@@ -384,6 +515,14 @@ export declare const lastNonEmpty: <A>(self: readonly [A, ...A[]]) => A;
|
|
|
384
515
|
*/
|
|
385
516
|
export declare const tail: <A>(self: Iterable<A>) => Option<Array<A>>;
|
|
386
517
|
/**
|
|
518
|
+
* Get all but the first element of a `NonEmptyReadonlyArray`.
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* import { Array } from "effect"
|
|
522
|
+
*
|
|
523
|
+
* const result = Array.tailNonEmpty([1, 2, 3, 4])
|
|
524
|
+
* assert.deepStrictEqual(result, [2, 3, 4])
|
|
525
|
+
*
|
|
387
526
|
* @category getters
|
|
388
527
|
* @since 2.0.0
|
|
389
528
|
*/
|
|
@@ -398,6 +537,12 @@ export declare const init: <A>(self: Iterable<A>) => Option<Array<A>>;
|
|
|
398
537
|
/**
|
|
399
538
|
* Get all but the last element of a non empty array, creating a new array.
|
|
400
539
|
*
|
|
540
|
+
* @example
|
|
541
|
+
* import { Array } from "effect"
|
|
542
|
+
*
|
|
543
|
+
* const result = Array.initNonEmpty([1, 2, 3, 4])
|
|
544
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
545
|
+
*
|
|
401
546
|
* @category getters
|
|
402
547
|
* @since 2.0.0
|
|
403
548
|
*/
|
|
@@ -407,6 +552,13 @@ export declare const initNonEmpty: <A>(self: readonly [A, ...A[]]) => Array<A>;
|
|
|
407
552
|
*
|
|
408
553
|
* **Note**. `n` is normalized to a non negative integer.
|
|
409
554
|
*
|
|
555
|
+
* @example
|
|
556
|
+
* import { Array } from "effect"
|
|
557
|
+
*
|
|
558
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
559
|
+
* const result = Array.take(numbers, 3)
|
|
560
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
561
|
+
*
|
|
410
562
|
* @category getters
|
|
411
563
|
* @since 2.0.0
|
|
412
564
|
*/
|
|
@@ -419,6 +571,13 @@ export declare const take: {
|
|
|
419
571
|
*
|
|
420
572
|
* **Note**. `n` is normalized to a non negative integer.
|
|
421
573
|
*
|
|
574
|
+
* @example
|
|
575
|
+
* import { Array } from "effect"
|
|
576
|
+
*
|
|
577
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
578
|
+
* const result = Array.takeRight(numbers, 3)
|
|
579
|
+
* assert.deepStrictEqual(result, [3, 4, 5])
|
|
580
|
+
*
|
|
422
581
|
* @category getters
|
|
423
582
|
* @since 2.0.0
|
|
424
583
|
*/
|
|
@@ -429,6 +588,19 @@ export declare const takeRight: {
|
|
|
429
588
|
/**
|
|
430
589
|
* Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.
|
|
431
590
|
*
|
|
591
|
+
* @example
|
|
592
|
+
* import { Array } from "effect"
|
|
593
|
+
*
|
|
594
|
+
* const numbers = [1, 3, 2, 4, 1, 2]
|
|
595
|
+
* const result = Array.takeWhile(numbers, x => x < 4)
|
|
596
|
+
* assert.deepStrictEqual(result, [1, 3, 2])
|
|
597
|
+
*
|
|
598
|
+
* // Explanation:
|
|
599
|
+
* // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.
|
|
600
|
+
* // - The next element (`3`) is also less than `4`, so it adds `3`.
|
|
601
|
+
* // - The next element (`2`) is again less than `4`, so it adds `2`.
|
|
602
|
+
* // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.
|
|
603
|
+
*
|
|
432
604
|
* @category getters
|
|
433
605
|
* @since 2.0.0
|
|
434
606
|
*/
|
|
@@ -458,6 +630,13 @@ export declare const span: {
|
|
|
458
630
|
*
|
|
459
631
|
* **Note**. `n` is normalized to a non negative integer.
|
|
460
632
|
*
|
|
633
|
+
* @example
|
|
634
|
+
* import { Array } from "effect"
|
|
635
|
+
*
|
|
636
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
637
|
+
* const result = Array.drop(numbers, 2)
|
|
638
|
+
* assert.deepStrictEqual(result, [3, 4, 5])
|
|
639
|
+
*
|
|
461
640
|
* @category getters
|
|
462
641
|
* @since 2.0.0
|
|
463
642
|
*/
|
|
@@ -470,6 +649,13 @@ export declare const drop: {
|
|
|
470
649
|
*
|
|
471
650
|
* **Note**. `n` is normalized to a non negative integer.
|
|
472
651
|
*
|
|
652
|
+
* @example
|
|
653
|
+
* import { Array } from "effect"
|
|
654
|
+
*
|
|
655
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
656
|
+
* const result = Array.dropRight(numbers, 2)
|
|
657
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
658
|
+
*
|
|
473
659
|
* @category getters
|
|
474
660
|
* @since 2.0.0
|
|
475
661
|
*/
|
|
@@ -480,6 +666,13 @@ export declare const dropRight: {
|
|
|
480
666
|
/**
|
|
481
667
|
* Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.
|
|
482
668
|
*
|
|
669
|
+
* @example
|
|
670
|
+
* import { Array } from "effect"
|
|
671
|
+
*
|
|
672
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
673
|
+
* const result = Array.dropWhile(numbers, x => x < 4)
|
|
674
|
+
* assert.deepStrictEqual(result, [4, 5])
|
|
675
|
+
*
|
|
483
676
|
* @category getters
|
|
484
677
|
* @since 2.0.0
|
|
485
678
|
*/
|
|
@@ -490,6 +683,13 @@ export declare const dropWhile: {
|
|
|
490
683
|
/**
|
|
491
684
|
* Return the first index for which a predicate holds.
|
|
492
685
|
*
|
|
686
|
+
* @example
|
|
687
|
+
* import { Array, Option } from "effect"
|
|
688
|
+
*
|
|
689
|
+
* const numbers = [5, 3, 8, 9]
|
|
690
|
+
* const result = Array.findFirstIndex(numbers, x => x > 5)
|
|
691
|
+
* assert.deepStrictEqual(result, Option.some(2))
|
|
692
|
+
*
|
|
493
693
|
* @category elements
|
|
494
694
|
* @since 2.0.0
|
|
495
695
|
*/
|
|
@@ -500,6 +700,13 @@ export declare const findFirstIndex: {
|
|
|
500
700
|
/**
|
|
501
701
|
* Return the last index for which a predicate holds.
|
|
502
702
|
*
|
|
703
|
+
* @example
|
|
704
|
+
* import { Array, Option } from "effect"
|
|
705
|
+
*
|
|
706
|
+
* const numbers = [1, 3, 8, 9]
|
|
707
|
+
* const result = Array.findLastIndex(numbers, x => x < 5)
|
|
708
|
+
* assert.deepStrictEqual(result, Option.some(1))
|
|
709
|
+
*
|
|
503
710
|
* @category elements
|
|
504
711
|
* @since 2.0.0
|
|
505
712
|
*/
|
|
@@ -511,6 +718,13 @@ export declare const findLastIndex: {
|
|
|
511
718
|
* Returns the first element that satisfies the specified
|
|
512
719
|
* predicate, or `None` if no such element exists.
|
|
513
720
|
*
|
|
721
|
+
* @example
|
|
722
|
+
* import { Array, Option } from "effect"
|
|
723
|
+
*
|
|
724
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
725
|
+
* const result = Array.findFirst(numbers, x => x > 3)
|
|
726
|
+
* assert.deepStrictEqual(result, Option.some(4))
|
|
727
|
+
*
|
|
514
728
|
* @category elements
|
|
515
729
|
* @since 2.0.0
|
|
516
730
|
*/
|
|
@@ -523,7 +737,15 @@ export declare const findFirst: {
|
|
|
523
737
|
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<A>;
|
|
524
738
|
};
|
|
525
739
|
/**
|
|
526
|
-
*
|
|
740
|
+
* Finds the last element in an iterable collection that satisfies the given predicate or refinement.
|
|
741
|
+
* Returns an `Option` containing the found element, or `Option.none` if no element matches.
|
|
742
|
+
*
|
|
743
|
+
* @example
|
|
744
|
+
* import { Array, Option } from "effect"
|
|
745
|
+
*
|
|
746
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
747
|
+
* const result = Array.findLast(numbers, n => n % 2 === 0)
|
|
748
|
+
* assert.deepStrictEqual(result, Option.some(4))
|
|
527
749
|
*
|
|
528
750
|
* @category elements
|
|
529
751
|
* @since 2.0.0
|
|
@@ -540,6 +762,13 @@ export declare const findLast: {
|
|
|
540
762
|
* Insert an element at the specified index, creating a new `NonEmptyArray`,
|
|
541
763
|
* or return `None` if the index is out of bounds.
|
|
542
764
|
*
|
|
765
|
+
* @example
|
|
766
|
+
* import { Array, Option } from "effect"
|
|
767
|
+
*
|
|
768
|
+
* const letters = ['a', 'b', 'c', 'e']
|
|
769
|
+
* const result = Array.insertAt(letters, 3, 'd')
|
|
770
|
+
* assert.deepStrictEqual(result, Option.some(['a', 'b', 'c', 'd', 'e']))
|
|
771
|
+
*
|
|
543
772
|
* @since 2.0.0
|
|
544
773
|
*/
|
|
545
774
|
export declare const insertAt: {
|
|
@@ -550,6 +779,13 @@ export declare const insertAt: {
|
|
|
550
779
|
* Change the element at the specified index, creating a new `Array`,
|
|
551
780
|
* or return a copy of the input if the index is out of bounds.
|
|
552
781
|
*
|
|
782
|
+
* @example
|
|
783
|
+
* import { Array } from "effect"
|
|
784
|
+
*
|
|
785
|
+
* const letters = ['a', 'b', 'c', 'd']
|
|
786
|
+
* const result = Array.replace(1, 'z')(letters)
|
|
787
|
+
* assert.deepStrictEqual(result, ['a', 'z', 'c', 'd'])
|
|
788
|
+
*
|
|
553
789
|
* @since 2.0.0
|
|
554
790
|
*/
|
|
555
791
|
export declare const replace: {
|
|
@@ -557,6 +793,15 @@ export declare const replace: {
|
|
|
557
793
|
<A, B>(self: Iterable<A>, i: number, b: B): Array<A | B>;
|
|
558
794
|
};
|
|
559
795
|
/**
|
|
796
|
+
* Replaces an element in an array with the given value, returning an option of the updated array.
|
|
797
|
+
*
|
|
798
|
+
* @example
|
|
799
|
+
* import { Array, Option } from "effect"
|
|
800
|
+
*
|
|
801
|
+
* const numbers = [1, 2, 3]
|
|
802
|
+
* const result = Array.replaceOption(numbers, 1, 4)
|
|
803
|
+
* assert.deepStrictEqual(result, Option.some([1, 4, 3]))
|
|
804
|
+
*
|
|
560
805
|
* @since 2.0.0
|
|
561
806
|
*/
|
|
562
807
|
export declare const replaceOption: {
|
|
@@ -567,6 +812,13 @@ export declare const replaceOption: {
|
|
|
567
812
|
* Apply a function to the element at the specified index, creating a new `Array`,
|
|
568
813
|
* or return a copy of the input if the index is out of bounds.
|
|
569
814
|
*
|
|
815
|
+
* @example
|
|
816
|
+
* import { Array } from "effect"
|
|
817
|
+
*
|
|
818
|
+
* const numbers = [1, 2, 3, 4]
|
|
819
|
+
* const result = Array.modify(numbers, 2, (n) => n * 2)
|
|
820
|
+
* assert.deepStrictEqual(result, [1, 2, 6, 4])
|
|
821
|
+
*
|
|
570
822
|
* @since 2.0.0
|
|
571
823
|
*/
|
|
572
824
|
export declare const modify: {
|
|
@@ -577,6 +829,16 @@ export declare const modify: {
|
|
|
577
829
|
* Apply a function to the element at the specified index, creating a new `Array`,
|
|
578
830
|
* or return `None` if the index is out of bounds.
|
|
579
831
|
*
|
|
832
|
+
* @example
|
|
833
|
+
* import { Array, Option } from "effect"
|
|
834
|
+
*
|
|
835
|
+
* const numbers = [1, 2, 3, 4]
|
|
836
|
+
* const result = Array.modifyOption(numbers, 2, (n) => n * 2)
|
|
837
|
+
* assert.deepStrictEqual(result, Option.some([1, 2, 6, 4]))
|
|
838
|
+
*
|
|
839
|
+
* const outOfBoundsResult = Array.modifyOption(numbers, 5, (n) => n * 2)
|
|
840
|
+
* assert.deepStrictEqual(outOfBoundsResult, Option.none())
|
|
841
|
+
*
|
|
580
842
|
* @since 2.0.0
|
|
581
843
|
*/
|
|
582
844
|
export declare const modifyOption: {
|
|
@@ -587,6 +849,16 @@ export declare const modifyOption: {
|
|
|
587
849
|
* Delete the element at the specified index, creating a new `Array`,
|
|
588
850
|
* or return a copy of the input if the index is out of bounds.
|
|
589
851
|
*
|
|
852
|
+
* @example
|
|
853
|
+
* import { Array } from "effect"
|
|
854
|
+
*
|
|
855
|
+
* const numbers = [1, 2, 3, 4]
|
|
856
|
+
* const result = Array.remove(numbers, 2)
|
|
857
|
+
* assert.deepStrictEqual(result, [1, 2, 4])
|
|
858
|
+
*
|
|
859
|
+
* const outOfBoundsResult = Array.remove(numbers, 5)
|
|
860
|
+
* assert.deepStrictEqual(outOfBoundsResult, [1, 2, 3, 4])
|
|
861
|
+
*
|
|
590
862
|
* @since 2.0.0
|
|
591
863
|
*/
|
|
592
864
|
export declare const remove: {
|
|
@@ -596,6 +868,13 @@ export declare const remove: {
|
|
|
596
868
|
/**
|
|
597
869
|
* Reverse an `Iterable`, creating a new `Array`.
|
|
598
870
|
*
|
|
871
|
+
* @example
|
|
872
|
+
* import { Array } from "effect"
|
|
873
|
+
*
|
|
874
|
+
* const numbers = [1, 2, 3, 4]
|
|
875
|
+
* const result = Array.reverse(numbers)
|
|
876
|
+
* assert.deepStrictEqual(result, [4, 3, 2, 1])
|
|
877
|
+
*
|
|
599
878
|
* @category elements
|
|
600
879
|
* @since 2.0.0
|
|
601
880
|
*/
|
|
@@ -613,6 +892,22 @@ export declare const sort: {
|
|
|
613
892
|
<A extends B, B>(self: Iterable<A>, O: Order.Order<B>): Array<A>;
|
|
614
893
|
};
|
|
615
894
|
/**
|
|
895
|
+
* Sorts an array based on a provided mapping function and order. The mapping
|
|
896
|
+
* function transforms the elements into a value that can be compared, and the
|
|
897
|
+
* order defines how those values should be sorted.
|
|
898
|
+
*
|
|
899
|
+
* @example
|
|
900
|
+
* import { Array, Order } from "effect"
|
|
901
|
+
*
|
|
902
|
+
* const strings = ["aaa", "b", "cc"]
|
|
903
|
+
* const result = Array.sortWith(strings, (s) => s.length, Order.number)
|
|
904
|
+
* assert.deepStrictEqual(result, ["b", "cc", "aaa"])
|
|
905
|
+
*
|
|
906
|
+
* // Explanation:
|
|
907
|
+
* // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`
|
|
908
|
+
* // converts each string into its length, and the `Order.number` specifies that the lengths should
|
|
909
|
+
* // be sorted in ascending order.
|
|
910
|
+
*
|
|
616
911
|
* @since 2.0.0
|
|
617
912
|
* @category elements
|
|
618
913
|
*/
|
|
@@ -622,8 +917,33 @@ export declare const sortWith: {
|
|
|
622
917
|
<A, B>(self: Iterable<A>, f: (a: A) => B, order: Order.Order<B>): Array<A>;
|
|
623
918
|
};
|
|
624
919
|
/**
|
|
625
|
-
*
|
|
626
|
-
* using first `orders
|
|
920
|
+
* Sorts the elements of an `Iterable` in increasing order based on the provided
|
|
921
|
+
* orders. The elements are compared using the first order in `orders`, then the
|
|
922
|
+
* second order if the first comparison is equal, and so on.
|
|
923
|
+
*
|
|
924
|
+
* @example
|
|
925
|
+
* import { Array, Order } from "effect"
|
|
926
|
+
*
|
|
927
|
+
* const users = [
|
|
928
|
+
* { name: "Alice", age: 30 },
|
|
929
|
+
* { name: "Bob", age: 25 },
|
|
930
|
+
* { name: "Charlie", age: 30 }
|
|
931
|
+
* ]
|
|
932
|
+
*
|
|
933
|
+
* const result = Array.sortBy(
|
|
934
|
+
* Order.mapInput(Order.number, (user: (typeof users)[number]) => user.age),
|
|
935
|
+
* Order.mapInput(Order.string, (user: (typeof users)[number]) => user.name)
|
|
936
|
+
* )(users)
|
|
937
|
+
*
|
|
938
|
+
* assert.deepStrictEqual(result, [
|
|
939
|
+
* { name: "Bob", age: 25 },
|
|
940
|
+
* { name: "Alice", age: 30 },
|
|
941
|
+
* { name: "Charlie", age: 30 }
|
|
942
|
+
* ])
|
|
943
|
+
*
|
|
944
|
+
* // Explanation:
|
|
945
|
+
* // The array of users is sorted first by age in ascending order. When ages are equal,
|
|
946
|
+
* // the users are further sorted by name in ascending order.
|
|
627
947
|
*
|
|
628
948
|
* @category sorting
|
|
629
949
|
* @since 2.0.0
|
|
@@ -634,6 +954,14 @@ export declare const sortBy: <S extends readonly [any, ...any[]] | Iterable<any>
|
|
|
634
954
|
* If one input `Iterable` is short, excess elements of the
|
|
635
955
|
* longer `Iterable` are discarded.
|
|
636
956
|
*
|
|
957
|
+
* @example
|
|
958
|
+
* import { Array } from "effect"
|
|
959
|
+
*
|
|
960
|
+
* const array1 = [1, 2, 3]
|
|
961
|
+
* const array2 = ['a', 'b']
|
|
962
|
+
* const result = Array.zip(array1, array2)
|
|
963
|
+
* assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])
|
|
964
|
+
*
|
|
637
965
|
* @category zipping
|
|
638
966
|
* @since 2.0.0
|
|
639
967
|
*/
|
|
@@ -647,6 +975,14 @@ export declare const zip: {
|
|
|
647
975
|
* Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one
|
|
648
976
|
* input `Iterable` is short, excess elements of the longer `Iterable` are discarded.
|
|
649
977
|
*
|
|
978
|
+
* @example
|
|
979
|
+
* import { Array } from "effect"
|
|
980
|
+
*
|
|
981
|
+
* const array1 = [1, 2, 3]
|
|
982
|
+
* const array2 = [4, 5, 6]
|
|
983
|
+
* const result = Array.zipWith(array1, array2, (a, b) => a + b)
|
|
984
|
+
* assert.deepStrictEqual(result, [5, 7, 9])
|
|
985
|
+
*
|
|
650
986
|
* @category zipping
|
|
651
987
|
* @since 2.0.0
|
|
652
988
|
*/
|
|
@@ -659,6 +995,12 @@ export declare const zipWith: {
|
|
|
659
995
|
/**
|
|
660
996
|
* This function is the inverse of `zip`. Takes an `Iterable` of pairs and return two corresponding `Array`s.
|
|
661
997
|
*
|
|
998
|
+
* @example
|
|
999
|
+
* import { Array } from "effect"
|
|
1000
|
+
*
|
|
1001
|
+
* const result = Array.unzip([[1, "a"], [2, "b"], [3, "c"]])
|
|
1002
|
+
* assert.deepStrictEqual(result, [[1, 2, 3], ['a', 'b', 'c']])
|
|
1003
|
+
*
|
|
662
1004
|
* @since 2.0.0
|
|
663
1005
|
*/
|
|
664
1006
|
export declare const unzip: <S extends Iterable<readonly [any, any]> | NonEmptyReadonlyArray<readonly [any, any]>>(self: S) => S extends NonEmptyReadonlyArray<readonly [infer A, infer B]> ? [NonEmptyArray<A>, NonEmptyArray<B>] : S extends Iterable<readonly [infer A, infer B]> ? [Array<A>, Array<B>] : never;
|
|
@@ -666,6 +1008,13 @@ export declare const unzip: <S extends Iterable<readonly [any, any]> | NonEmptyR
|
|
|
666
1008
|
* Places an element in between members of an `Iterable`.
|
|
667
1009
|
* If the input is a non-empty array, the result is also a non-empty array.
|
|
668
1010
|
*
|
|
1011
|
+
* @example
|
|
1012
|
+
* import { Array } from "effect"
|
|
1013
|
+
*
|
|
1014
|
+
* const numbers = [1, 2, 3]
|
|
1015
|
+
* const result = Array.intersperse(numbers, 0)
|
|
1016
|
+
* assert.deepStrictEqual(result, [1, 0, 2, 0, 3])
|
|
1017
|
+
*
|
|
669
1018
|
* @since 2.0.0
|
|
670
1019
|
*/
|
|
671
1020
|
export declare const intersperse: {
|
|
@@ -676,6 +1025,12 @@ export declare const intersperse: {
|
|
|
676
1025
|
/**
|
|
677
1026
|
* Apply a function to the head, creating a new `NonEmptyReadonlyArray`.
|
|
678
1027
|
*
|
|
1028
|
+
* @example
|
|
1029
|
+
* import { Array } from "effect"
|
|
1030
|
+
*
|
|
1031
|
+
* const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)
|
|
1032
|
+
* assert.deepStrictEqual(result, [10, 2, 3])
|
|
1033
|
+
*
|
|
679
1034
|
* @since 2.0.0
|
|
680
1035
|
*/
|
|
681
1036
|
export declare const modifyNonEmptyHead: {
|
|
@@ -685,6 +1040,12 @@ export declare const modifyNonEmptyHead: {
|
|
|
685
1040
|
/**
|
|
686
1041
|
* Change the head, creating a new `NonEmptyReadonlyArray`.
|
|
687
1042
|
*
|
|
1043
|
+
* @example
|
|
1044
|
+
* import { Array } from "effect"
|
|
1045
|
+
*
|
|
1046
|
+
* const result = Array.setNonEmptyHead([1, 2, 3], 10)
|
|
1047
|
+
* assert.deepStrictEqual(result, [10, 2, 3])
|
|
1048
|
+
*
|
|
688
1049
|
* @since 2.0.0
|
|
689
1050
|
*/
|
|
690
1051
|
export declare const setNonEmptyHead: {
|
|
@@ -694,6 +1055,12 @@ export declare const setNonEmptyHead: {
|
|
|
694
1055
|
/**
|
|
695
1056
|
* Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.
|
|
696
1057
|
*
|
|
1058
|
+
* @example
|
|
1059
|
+
* import { Array } from "effect"
|
|
1060
|
+
*
|
|
1061
|
+
* const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)
|
|
1062
|
+
* assert.deepStrictEqual(result, [1, 2, 6])
|
|
1063
|
+
*
|
|
697
1064
|
* @since 2.0.0
|
|
698
1065
|
*/
|
|
699
1066
|
export declare const modifyNonEmptyLast: {
|
|
@@ -703,6 +1070,12 @@ export declare const modifyNonEmptyLast: {
|
|
|
703
1070
|
/**
|
|
704
1071
|
* Change the last element, creating a new `NonEmptyReadonlyArray`.
|
|
705
1072
|
*
|
|
1073
|
+
* @example
|
|
1074
|
+
* import { Array } from "effect"
|
|
1075
|
+
*
|
|
1076
|
+
* const result = Array.setNonEmptyLast([1, 2, 3], 4)
|
|
1077
|
+
* assert.deepStrictEqual(result, [1, 2, 4])
|
|
1078
|
+
*
|
|
706
1079
|
* @since 2.0.0
|
|
707
1080
|
*/
|
|
708
1081
|
export declare const setNonEmptyLast: {
|
|
@@ -713,6 +1086,13 @@ export declare const setNonEmptyLast: {
|
|
|
713
1086
|
* Rotate an `Iterable` by `n` steps.
|
|
714
1087
|
* If the input is a non-empty array, the result is also a non-empty array.
|
|
715
1088
|
*
|
|
1089
|
+
* @example
|
|
1090
|
+
* import { Array } from "effect"
|
|
1091
|
+
*
|
|
1092
|
+
* const letters = ['a', 'b', 'c', 'd']
|
|
1093
|
+
* const result = Array.rotate(letters, 2)
|
|
1094
|
+
* assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])
|
|
1095
|
+
*
|
|
716
1096
|
* @since 2.0.0
|
|
717
1097
|
*/
|
|
718
1098
|
export declare const rotate: {
|
|
@@ -723,6 +1103,15 @@ export declare const rotate: {
|
|
|
723
1103
|
/**
|
|
724
1104
|
* Returns a function that checks if a `ReadonlyArray` contains a given value using a provided `isEquivalent` function.
|
|
725
1105
|
*
|
|
1106
|
+
* @example
|
|
1107
|
+
* import { Array } from "effect"
|
|
1108
|
+
*
|
|
1109
|
+
* const numbers = [1, 2, 3, 4]
|
|
1110
|
+
* const isEquivalent = (a: number, b: number) => a === b
|
|
1111
|
+
* const containsNumber = Array.containsWith(isEquivalent)
|
|
1112
|
+
* const result = containsNumber(3)(numbers)
|
|
1113
|
+
* assert.deepStrictEqual(result, true)
|
|
1114
|
+
*
|
|
726
1115
|
* @category elements
|
|
727
1116
|
* @since 2.0.0
|
|
728
1117
|
*/
|
|
@@ -733,6 +1122,13 @@ export declare const containsWith: <A>(isEquivalent: (self: A, that: A) => boole
|
|
|
733
1122
|
/**
|
|
734
1123
|
* Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.
|
|
735
1124
|
*
|
|
1125
|
+
* @example
|
|
1126
|
+
* import { Array } from "effect"
|
|
1127
|
+
*
|
|
1128
|
+
* const letters = ['a', 'b', 'c', 'd']
|
|
1129
|
+
* const result = Array.contains('c')(letters)
|
|
1130
|
+
* assert.deepStrictEqual(result, true)
|
|
1131
|
+
*
|
|
736
1132
|
* @category elements
|
|
737
1133
|
* @since 2.0.0
|
|
738
1134
|
*/
|
|
@@ -745,6 +1141,18 @@ export declare const contains: {
|
|
|
745
1141
|
* `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a
|
|
746
1142
|
* value and the rest of the `Array`.
|
|
747
1143
|
*
|
|
1144
|
+
* @example
|
|
1145
|
+
* import { Array } from "effect"
|
|
1146
|
+
*
|
|
1147
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1148
|
+
* const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])
|
|
1149
|
+
* assert.deepStrictEqual(result, [2, 4, 6, 8, 10])
|
|
1150
|
+
*
|
|
1151
|
+
* // Explanation:
|
|
1152
|
+
* // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.
|
|
1153
|
+
* // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,
|
|
1154
|
+
* // resulting in a new array `[2, 4, 6, 8, 10]`.
|
|
1155
|
+
*
|
|
748
1156
|
* @since 2.0.0
|
|
749
1157
|
*/
|
|
750
1158
|
export declare const chop: {
|
|
@@ -756,6 +1164,13 @@ export declare const chop: {
|
|
|
756
1164
|
* Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.
|
|
757
1165
|
* The value of `n` can be `0`.
|
|
758
1166
|
*
|
|
1167
|
+
* @example
|
|
1168
|
+
* import { Array } from "effect"
|
|
1169
|
+
*
|
|
1170
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1171
|
+
* const result = Array.splitAt(numbers, 3)
|
|
1172
|
+
* assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])
|
|
1173
|
+
*
|
|
759
1174
|
* @category splitting
|
|
760
1175
|
* @since 2.0.0
|
|
761
1176
|
*/
|
|
@@ -767,6 +1182,12 @@ export declare const splitAt: {
|
|
|
767
1182
|
* Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.
|
|
768
1183
|
* The value of `n` must be `>= 1`.
|
|
769
1184
|
*
|
|
1185
|
+
* @example
|
|
1186
|
+
* import { Array } from "effect"
|
|
1187
|
+
*
|
|
1188
|
+
* const result = Array.splitNonEmptyAt(["a", "b", "c", "d", "e"], 3)
|
|
1189
|
+
* assert.deepStrictEqual(result, [["a", "b", "c"], ["d", "e"]])
|
|
1190
|
+
*
|
|
770
1191
|
* @category splitting
|
|
771
1192
|
* @since 2.0.0
|
|
772
1193
|
*/
|
|
@@ -777,6 +1198,13 @@ export declare const splitNonEmptyAt: {
|
|
|
777
1198
|
/**
|
|
778
1199
|
* Splits this iterable into `n` equally sized arrays.
|
|
779
1200
|
*
|
|
1201
|
+
* @example
|
|
1202
|
+
* import { Array } from "effect"
|
|
1203
|
+
*
|
|
1204
|
+
* const numbers = [1, 2, 3, 4, 5, 6, 7, 8]
|
|
1205
|
+
* const result = Array.split(numbers, 3)
|
|
1206
|
+
* assert.deepStrictEqual(result, [[1, 2, 3], [4, 5, 6], [7, 8]])
|
|
1207
|
+
*
|
|
780
1208
|
* @since 2.0.0
|
|
781
1209
|
* @category splitting
|
|
782
1210
|
*/
|
|
@@ -788,6 +1216,13 @@ export declare const split: {
|
|
|
788
1216
|
* Splits this iterable on the first element that matches this predicate.
|
|
789
1217
|
* Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.
|
|
790
1218
|
*
|
|
1219
|
+
* @example
|
|
1220
|
+
* import { Array } from "effect"
|
|
1221
|
+
*
|
|
1222
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1223
|
+
* const result = Array.splitWhere(numbers, n => n > 3)
|
|
1224
|
+
* assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])
|
|
1225
|
+
*
|
|
791
1226
|
* @category splitting
|
|
792
1227
|
* @since 2.0.0
|
|
793
1228
|
*/
|
|
@@ -796,6 +1231,15 @@ export declare const splitWhere: {
|
|
|
796
1231
|
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [beforeMatch: Array<A>, fromMatch: Array<A>];
|
|
797
1232
|
};
|
|
798
1233
|
/**
|
|
1234
|
+
* Copies an array.
|
|
1235
|
+
*
|
|
1236
|
+
* @example
|
|
1237
|
+
* import { Array } from "effect"
|
|
1238
|
+
*
|
|
1239
|
+
* const numbers = [1, 2, 3]
|
|
1240
|
+
* const copy = Array.copy(numbers)
|
|
1241
|
+
* assert.deepStrictEqual(copy, [1, 2, 3])
|
|
1242
|
+
*
|
|
799
1243
|
* @since 2.0.0
|
|
800
1244
|
*/
|
|
801
1245
|
export declare const copy: {
|
|
@@ -813,6 +1257,19 @@ export declare const copy: {
|
|
|
813
1257
|
*
|
|
814
1258
|
* whenever `n` evenly divides the length of `self`.
|
|
815
1259
|
*
|
|
1260
|
+
* @example
|
|
1261
|
+
* import { Array } from "effect"
|
|
1262
|
+
*
|
|
1263
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1264
|
+
* const result = Array.chunksOf(numbers, 2)
|
|
1265
|
+
* assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])
|
|
1266
|
+
*
|
|
1267
|
+
* // Explanation:
|
|
1268
|
+
* // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.
|
|
1269
|
+
* // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,
|
|
1270
|
+
* // the last chunk contains the remaining elements.
|
|
1271
|
+
* // The result is `[[1, 2], [3, 4], [5]]`.
|
|
1272
|
+
*
|
|
816
1273
|
* @category splitting
|
|
817
1274
|
* @since 2.0.0
|
|
818
1275
|
*/
|
|
@@ -824,6 +1281,12 @@ export declare const chunksOf: {
|
|
|
824
1281
|
/**
|
|
825
1282
|
* Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.
|
|
826
1283
|
*
|
|
1284
|
+
* @example
|
|
1285
|
+
* import { Array } from "effect"
|
|
1286
|
+
*
|
|
1287
|
+
* const result = Array.groupWith(["a", "a", "b", "b", "b", "c", "a"], (x, y) => x === y)
|
|
1288
|
+
* assert.deepStrictEqual(result, [["a", "a"], ["b", "b", "b"], ["c"], ["a"]])
|
|
1289
|
+
*
|
|
827
1290
|
* @category grouping
|
|
828
1291
|
* @since 2.0.0
|
|
829
1292
|
*/
|
|
@@ -834,6 +1297,12 @@ export declare const groupWith: {
|
|
|
834
1297
|
/**
|
|
835
1298
|
* Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s.
|
|
836
1299
|
*
|
|
1300
|
+
* @example
|
|
1301
|
+
* import { Array } from "effect"
|
|
1302
|
+
*
|
|
1303
|
+
* const result = Array.group([1, 1, 2, 2, 2, 3, 1])
|
|
1304
|
+
* assert.deepStrictEqual(result, [[1, 1], [2, 2, 2], [3], [1]])
|
|
1305
|
+
*
|
|
837
1306
|
* @category grouping
|
|
838
1307
|
* @since 2.0.0
|
|
839
1308
|
*/
|
|
@@ -842,6 +1311,20 @@ export declare const group: <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray
|
|
|
842
1311
|
* Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning
|
|
843
1312
|
* function on each element, and grouping the results according to values returned
|
|
844
1313
|
*
|
|
1314
|
+
* @example
|
|
1315
|
+
* import { Array } from "effect"
|
|
1316
|
+
*
|
|
1317
|
+
* const people = [
|
|
1318
|
+
* { name: "Alice", group: "A" },
|
|
1319
|
+
* { name: "Bob", group: "B" },
|
|
1320
|
+
* { name: "Charlie", group: "A" }
|
|
1321
|
+
* ]
|
|
1322
|
+
* const result = Array.groupBy(people, person => person.group)
|
|
1323
|
+
* assert.deepStrictEqual(result, {
|
|
1324
|
+
* A: [{ name: "Alice", group: "A" }, { name: "Charlie", group: "A" }],
|
|
1325
|
+
* B: [{ name: "Bob", group: "B" }]
|
|
1326
|
+
* })
|
|
1327
|
+
*
|
|
845
1328
|
* @category grouping
|
|
846
1329
|
* @since 2.0.0
|
|
847
1330
|
*/
|
|
@@ -850,6 +1333,16 @@ export declare const groupBy: {
|
|
|
850
1333
|
<A, K extends string | symbol>(self: Iterable<A>, f: (a: A) => K): Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>>;
|
|
851
1334
|
};
|
|
852
1335
|
/**
|
|
1336
|
+
* Calculates the union of two arrays using the provided equivalence relation.
|
|
1337
|
+
*
|
|
1338
|
+
* @example
|
|
1339
|
+
* import { Array } from "effect"
|
|
1340
|
+
*
|
|
1341
|
+
* const array1 = [1, 2]
|
|
1342
|
+
* const array2 = [2, 3]
|
|
1343
|
+
* const union = Array.unionWith(array1, array2, (a, b) => a === b)
|
|
1344
|
+
* assert.deepStrictEqual(union, [1, 2, 3])
|
|
1345
|
+
*
|
|
853
1346
|
* @since 2.0.0
|
|
854
1347
|
*/
|
|
855
1348
|
export declare const unionWith: {
|
|
@@ -859,6 +1352,16 @@ export declare const unionWith: {
|
|
|
859
1352
|
<A, B>(self: Iterable<A>, that: Iterable<B>, isEquivalent: (self: A, that: B) => boolean): Array<A | B>;
|
|
860
1353
|
};
|
|
861
1354
|
/**
|
|
1355
|
+
* Creates a union of two arrays, removing duplicates.
|
|
1356
|
+
*
|
|
1357
|
+
* @example
|
|
1358
|
+
* import { Array } from "effect"
|
|
1359
|
+
*
|
|
1360
|
+
* const array1 = [1, 2]
|
|
1361
|
+
* const array2 = [2, 3]
|
|
1362
|
+
* const result = Array.union(array1, array2)
|
|
1363
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
1364
|
+
*
|
|
862
1365
|
* @since 2.0.0
|
|
863
1366
|
*/
|
|
864
1367
|
export declare const union: {
|
|
@@ -871,6 +1374,15 @@ export declare const union: {
|
|
|
871
1374
|
* Creates an `Array` of unique values that are included in all given `Iterable`s using the provided `isEquivalent` function.
|
|
872
1375
|
* The order and references of result values are determined by the first `Iterable`.
|
|
873
1376
|
*
|
|
1377
|
+
* @example
|
|
1378
|
+
* import { Array } from "effect"
|
|
1379
|
+
*
|
|
1380
|
+
* const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }]
|
|
1381
|
+
* const array2 = [{ id: 3 }, { id: 4 }, { id: 1 }]
|
|
1382
|
+
* const isEquivalent = (a: { id: number }, b: { id: number }) => a.id === b.id
|
|
1383
|
+
* const result = Array.intersectionWith(isEquivalent)(array2)(array1)
|
|
1384
|
+
* assert.deepStrictEqual(result, [{ id: 1 }, { id: 3 }])
|
|
1385
|
+
*
|
|
874
1386
|
* @since 2.0.0
|
|
875
1387
|
*/
|
|
876
1388
|
export declare const intersectionWith: <A>(isEquivalent: (self: A, that: A) => boolean) => {
|
|
@@ -881,6 +1393,14 @@ export declare const intersectionWith: <A>(isEquivalent: (self: A, that: A) => b
|
|
|
881
1393
|
* Creates an `Array` of unique values that are included in all given `Iterable`s.
|
|
882
1394
|
* The order and references of result values are determined by the first `Iterable`.
|
|
883
1395
|
*
|
|
1396
|
+
* @example
|
|
1397
|
+
* import { Array } from "effect"
|
|
1398
|
+
*
|
|
1399
|
+
* const array1 = [1, 2, 3]
|
|
1400
|
+
* const array2 = [3, 4, 1]
|
|
1401
|
+
* const result = Array.intersection(array1, array2)
|
|
1402
|
+
* assert.deepStrictEqual(result, [1, 3])
|
|
1403
|
+
*
|
|
884
1404
|
* @since 2.0.0
|
|
885
1405
|
*/
|
|
886
1406
|
export declare const intersection: {
|
|
@@ -891,6 +1411,14 @@ export declare const intersection: {
|
|
|
891
1411
|
* Creates a `Array` of values not included in the other given `Iterable` using the provided `isEquivalent` function.
|
|
892
1412
|
* The order and references of result values are determined by the first `Iterable`.
|
|
893
1413
|
*
|
|
1414
|
+
* @example
|
|
1415
|
+
* import { Array } from "effect"
|
|
1416
|
+
*
|
|
1417
|
+
* const array1 = [1, 2, 3]
|
|
1418
|
+
* const array2 = [2, 3, 4]
|
|
1419
|
+
* const difference = Array.differenceWith<number>((a, b) => a === b)(array1, array2)
|
|
1420
|
+
* assert.deepStrictEqual(difference, [1])
|
|
1421
|
+
*
|
|
894
1422
|
* @since 2.0.0
|
|
895
1423
|
*/
|
|
896
1424
|
export declare const differenceWith: <A>(isEquivalent: (self: A, that: A) => boolean) => {
|
|
@@ -901,6 +1429,14 @@ export declare const differenceWith: <A>(isEquivalent: (self: A, that: A) => boo
|
|
|
901
1429
|
* Creates a `Array` of values not included in the other given `Iterable`.
|
|
902
1430
|
* The order and references of result values are determined by the first `Iterable`.
|
|
903
1431
|
*
|
|
1432
|
+
* @example
|
|
1433
|
+
* import { Array } from "effect"
|
|
1434
|
+
*
|
|
1435
|
+
* const array1 = [1, 2, 3]
|
|
1436
|
+
* const array2 = [2, 3, 4]
|
|
1437
|
+
* const difference = Array.difference(array1, array2)
|
|
1438
|
+
* assert.deepStrictEqual(difference, [1])
|
|
1439
|
+
*
|
|
904
1440
|
* @since 2.0.0
|
|
905
1441
|
*/
|
|
906
1442
|
export declare const difference: {
|
|
@@ -964,13 +1500,35 @@ export declare const flatMap: {
|
|
|
964
1500
|
<A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => ReadonlyArray<B>): Array<B>;
|
|
965
1501
|
};
|
|
966
1502
|
/**
|
|
967
|
-
*
|
|
1503
|
+
* Combines multiple arrays into a single array by concatenating all elements
|
|
1504
|
+
* from each nested array. This function ensures that the structure of nested
|
|
1505
|
+
* arrays is collapsed into a single, flat array.
|
|
1506
|
+
*
|
|
1507
|
+
* @example
|
|
1508
|
+
* import { Array } from "effect";
|
|
1509
|
+
*
|
|
1510
|
+
* const nestedArrays = [[1, 2], [], [3, 4], [], [5, 6]]
|
|
1511
|
+
* const result = Array.flatten(nestedArrays)
|
|
1512
|
+
*
|
|
1513
|
+
* assert.deepStrictEqual(result, [1, 2, 3, 4, 5, 6]);
|
|
968
1514
|
*
|
|
969
1515
|
* @category sequencing
|
|
970
1516
|
* @since 2.0.0
|
|
971
1517
|
*/
|
|
972
1518
|
export declare const flatten: <S extends ReadonlyArray<ReadonlyArray<any>>>(self: S) => ReadonlyArray.Flatten<S>;
|
|
973
1519
|
/**
|
|
1520
|
+
* Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.
|
|
1521
|
+
* This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.
|
|
1522
|
+
*
|
|
1523
|
+
* @example
|
|
1524
|
+
* import { Array, Option } from "effect";
|
|
1525
|
+
*
|
|
1526
|
+
* const data = [1, 2, 3, 4, 5];
|
|
1527
|
+
* const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();
|
|
1528
|
+
* const result = Array.filterMap(data, evenSquares);
|
|
1529
|
+
*
|
|
1530
|
+
* assert.deepStrictEqual(result, [4, 16]);
|
|
1531
|
+
*
|
|
974
1532
|
* @category filtering
|
|
975
1533
|
* @since 2.0.0
|
|
976
1534
|
*/
|
|
@@ -979,7 +1537,18 @@ export declare const filterMap: {
|
|
|
979
1537
|
<A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B>;
|
|
980
1538
|
};
|
|
981
1539
|
/**
|
|
982
|
-
*
|
|
1540
|
+
* Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.
|
|
1541
|
+
* This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.
|
|
1542
|
+
* This is useful when you need to transform an array but only up to the point where a certain condition holds true.
|
|
1543
|
+
*
|
|
1544
|
+
* @example
|
|
1545
|
+
* import { Array, Option } from "effect";
|
|
1546
|
+
*
|
|
1547
|
+
* const data = [2, 4, 5];
|
|
1548
|
+
* const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();
|
|
1549
|
+
* const result = Array.filterMapWhile(data, toSquareTillOdd);
|
|
1550
|
+
*
|
|
1551
|
+
* assert.deepStrictEqual(result, [4, 16]);
|
|
983
1552
|
*
|
|
984
1553
|
* @category filtering
|
|
985
1554
|
* @since 2.0.0
|
|
@@ -989,6 +1558,25 @@ export declare const filterMapWhile: {
|
|
|
989
1558
|
<A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B>;
|
|
990
1559
|
};
|
|
991
1560
|
/**
|
|
1561
|
+
* Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.
|
|
1562
|
+
* This function is particularly useful for operations where each element can result in two possible types,
|
|
1563
|
+
* and you want to separate these types into different collections. For instance, separating validation results
|
|
1564
|
+
* into successes and failures.
|
|
1565
|
+
*
|
|
1566
|
+
* @example
|
|
1567
|
+
* import { Array, Either } from "effect";
|
|
1568
|
+
*
|
|
1569
|
+
* const data = [1, 2, 3, 4, 5]
|
|
1570
|
+
* const isEven = (x: number) => x % 2 === 0
|
|
1571
|
+
* const partitioned = Array.partitionMap(data, x =>
|
|
1572
|
+
* isEven(x) ? Either.right(x) : Either.left(x)
|
|
1573
|
+
* )
|
|
1574
|
+
*
|
|
1575
|
+
* assert.deepStrictEqual(partitioned, [
|
|
1576
|
+
* [1, 3, 5],
|
|
1577
|
+
* [2, 4]
|
|
1578
|
+
* ])
|
|
1579
|
+
*
|
|
992
1580
|
* @category filtering
|
|
993
1581
|
* @since 2.0.0
|
|
994
1582
|
*/
|
|
@@ -1064,11 +1652,29 @@ export declare const partition: {
|
|
|
1064
1652
|
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [excluded: Array<A>, satisfying: Array<A>];
|
|
1065
1653
|
};
|
|
1066
1654
|
/**
|
|
1655
|
+
* Separates an `Iterable` into two arrays based on a predicate.
|
|
1656
|
+
*
|
|
1657
|
+
* @example
|
|
1658
|
+
* import { Array } from "effect"
|
|
1659
|
+
*
|
|
1660
|
+
* const numbers = [1, 2, 3, 4]
|
|
1661
|
+
* const result = Array.partition(numbers, n => n % 2 === 0)
|
|
1662
|
+
* assert.deepStrictEqual(result, [[1, 3], [2, 4]])
|
|
1663
|
+
*
|
|
1067
1664
|
* @category filtering
|
|
1068
1665
|
* @since 2.0.0
|
|
1069
1666
|
*/
|
|
1070
1667
|
export declare const separate: <R, L>(self: Iterable<Either<R, L>>) => [Array<L>, Array<R>];
|
|
1071
1668
|
/**
|
|
1669
|
+
* Reduces an array from the left.
|
|
1670
|
+
*
|
|
1671
|
+
* @example
|
|
1672
|
+
* import { Array } from "effect"
|
|
1673
|
+
*
|
|
1674
|
+
* const numbers = [1, 2, 3]
|
|
1675
|
+
* const result = Array.reduce(numbers, 0, (acc, n) => acc + n)
|
|
1676
|
+
* assert.deepStrictEqual(result, 6)
|
|
1677
|
+
*
|
|
1072
1678
|
* @category folding
|
|
1073
1679
|
* @since 2.0.0
|
|
1074
1680
|
*/
|
|
@@ -1077,6 +1683,15 @@ export declare const reduce: {
|
|
|
1077
1683
|
<A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B;
|
|
1078
1684
|
};
|
|
1079
1685
|
/**
|
|
1686
|
+
* Reduces an array from the right.
|
|
1687
|
+
*
|
|
1688
|
+
* @example
|
|
1689
|
+
* import { Array } from "effect"
|
|
1690
|
+
*
|
|
1691
|
+
* const numbers = [1, 2, 3]
|
|
1692
|
+
* const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n)
|
|
1693
|
+
* assert.deepStrictEqual(result, 6)
|
|
1694
|
+
*
|
|
1080
1695
|
* @category folding
|
|
1081
1696
|
* @since 2.0.0
|
|
1082
1697
|
*/
|
|
@@ -1085,6 +1700,16 @@ export declare const reduceRight: {
|
|
|
1085
1700
|
<A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B;
|
|
1086
1701
|
};
|
|
1087
1702
|
/**
|
|
1703
|
+
* Lifts a predicate into an array.
|
|
1704
|
+
*
|
|
1705
|
+
* @example
|
|
1706
|
+
* import { Array } from "effect"
|
|
1707
|
+
*
|
|
1708
|
+
* const isEven = (n: number) => n % 2 === 0
|
|
1709
|
+
* const to = Array.liftPredicate(isEven)
|
|
1710
|
+
* assert.deepStrictEqual(to(1), [])
|
|
1711
|
+
* assert.deepStrictEqual(to(2), [2])
|
|
1712
|
+
*
|
|
1088
1713
|
* @category lifting
|
|
1089
1714
|
* @since 2.0.0
|
|
1090
1715
|
*/
|
|
@@ -1108,6 +1733,20 @@ export declare const fromNullable: <A>(a: A) => Array<NonNullable<A>>;
|
|
|
1108
1733
|
*/
|
|
1109
1734
|
export declare const liftNullable: <A extends unknown[], B>(f: (...a: A) => B | null | undefined) => (...a: A) => Array<NonNullable<B>>;
|
|
1110
1735
|
/**
|
|
1736
|
+
* Maps over an array and flattens the result, removing null and undefined values.
|
|
1737
|
+
*
|
|
1738
|
+
* @example
|
|
1739
|
+
* import { Array } from "effect"
|
|
1740
|
+
*
|
|
1741
|
+
* const numbers = [1, 2, 3]
|
|
1742
|
+
* const result = Array.flatMapNullable(numbers, n => (n % 2 === 0 ? null : n))
|
|
1743
|
+
* assert.deepStrictEqual(result, [1, 3])
|
|
1744
|
+
*
|
|
1745
|
+
* // Explanation:
|
|
1746
|
+
* // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers
|
|
1747
|
+
* // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened
|
|
1748
|
+
* // to remove null values, resulting in [1, 3].
|
|
1749
|
+
*
|
|
1111
1750
|
* @category sequencing
|
|
1112
1751
|
* @since 2.0.0
|
|
1113
1752
|
*/
|
|
@@ -1116,6 +1755,29 @@ export declare const flatMapNullable: {
|
|
|
1116
1755
|
<A, B>(self: ReadonlyArray<A>, f: (a: A) => B | null | undefined): Array<NonNullable<B>>;
|
|
1117
1756
|
};
|
|
1118
1757
|
/**
|
|
1758
|
+
* Lifts a function that returns an `Either` into a function that returns an array.
|
|
1759
|
+
* If the `Either` is a left, it returns an empty array.
|
|
1760
|
+
* If the `Either` is a right, it returns an array with the right value.
|
|
1761
|
+
*
|
|
1762
|
+
* @example
|
|
1763
|
+
* import { Array, Either } from "effect"
|
|
1764
|
+
*
|
|
1765
|
+
* const parseNumber = (s: string): Either.Either<number, Error> =>
|
|
1766
|
+
* isNaN(Number(s)) ? Either.left(new Error("Not a number")) : Either.right(Number(s))
|
|
1767
|
+
*
|
|
1768
|
+
* const liftedParseNumber = Array.liftEither(parseNumber)
|
|
1769
|
+
*
|
|
1770
|
+
* const result1 = liftedParseNumber("42")
|
|
1771
|
+
* assert.deepStrictEqual(result1, [42])
|
|
1772
|
+
*
|
|
1773
|
+
* const result2 = liftedParseNumber("not a number")
|
|
1774
|
+
* assert.deepStrictEqual(result2, [])
|
|
1775
|
+
*
|
|
1776
|
+
* // Explanation:
|
|
1777
|
+
* // The function parseNumber is lifted to return an array.
|
|
1778
|
+
* // When parsing "42", it returns an Either.left with the number 42, resulting in [42].
|
|
1779
|
+
* // When parsing "not a number", it returns an Either.right with an error, resulting in an empty array [].
|
|
1780
|
+
*
|
|
1119
1781
|
* @category lifting
|
|
1120
1782
|
* @since 2.0.0
|
|
1121
1783
|
*/
|
|
@@ -1143,6 +1805,21 @@ export declare const some: {
|
|
|
1143
1805
|
<A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>;
|
|
1144
1806
|
};
|
|
1145
1807
|
/**
|
|
1808
|
+
* Extends an array with a function that maps each subarray to a value.
|
|
1809
|
+
*
|
|
1810
|
+
* @example
|
|
1811
|
+
* import { Array } from "effect"
|
|
1812
|
+
*
|
|
1813
|
+
* const numbers = [1, 2, 3]
|
|
1814
|
+
* const result = Array.extend(numbers, as => as.length)
|
|
1815
|
+
* assert.deepStrictEqual(result, [3, 2, 1])
|
|
1816
|
+
*
|
|
1817
|
+
* // Explanation:
|
|
1818
|
+
* // The function maps each subarray starting from each element to its length.
|
|
1819
|
+
* // The subarrays are: [1, 2, 3], [2, 3], [3].
|
|
1820
|
+
* // The lengths are: 3, 2, 1.
|
|
1821
|
+
* // Therefore, the result is [3, 2, 1].
|
|
1822
|
+
*
|
|
1146
1823
|
* @since 2.0.0
|
|
1147
1824
|
*/
|
|
1148
1825
|
export declare const extend: {
|
|
@@ -1150,6 +1827,14 @@ export declare const extend: {
|
|
|
1150
1827
|
<A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B>;
|
|
1151
1828
|
};
|
|
1152
1829
|
/**
|
|
1830
|
+
* Finds the minimum element in an array based on a comparator.
|
|
1831
|
+
*
|
|
1832
|
+
* @example
|
|
1833
|
+
* import { Array, Order } from "effect"
|
|
1834
|
+
*
|
|
1835
|
+
* const min = Array.min([3, 1, 2], Order.number)
|
|
1836
|
+
* assert.deepStrictEqual(min, 1)
|
|
1837
|
+
*
|
|
1153
1838
|
* @since 2.0.0
|
|
1154
1839
|
*/
|
|
1155
1840
|
export declare const min: {
|
|
@@ -1157,6 +1842,14 @@ export declare const min: {
|
|
|
1157
1842
|
<A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A;
|
|
1158
1843
|
};
|
|
1159
1844
|
/**
|
|
1845
|
+
* Finds the maximum element in an array based on a comparator.
|
|
1846
|
+
*
|
|
1847
|
+
* @example
|
|
1848
|
+
* import { Array, Order } from "effect"
|
|
1849
|
+
*
|
|
1850
|
+
* const max = Array.max([3, 1, 2], Order.number)
|
|
1851
|
+
* assert.deepStrictEqual(max, 3)
|
|
1852
|
+
*
|
|
1160
1853
|
* @since 2.0.0
|
|
1161
1854
|
*/
|
|
1162
1855
|
export declare const max: {
|
|
@@ -1179,12 +1872,28 @@ export declare const unfold: <B, A>(b: B, f: (b: B) => Option<readonly [A, B]>)
|
|
|
1179
1872
|
*/
|
|
1180
1873
|
export declare const getOrder: <A>(O: Order.Order<A>) => Order.Order<ReadonlyArray<A>>;
|
|
1181
1874
|
/**
|
|
1875
|
+
* Creates an equivalence relation for arrays.
|
|
1876
|
+
*
|
|
1877
|
+
* @example
|
|
1878
|
+
* import { Array } from "effect"
|
|
1879
|
+
*
|
|
1880
|
+
* const numbers1 = [1, 2, 3]
|
|
1881
|
+
* const numbers2 = [1, 2, 3]
|
|
1882
|
+
* const eq = Array.getEquivalence<number>((a, b) => a === b)
|
|
1883
|
+
* assert.deepStrictEqual(eq(numbers1, numbers2), true)
|
|
1884
|
+
*
|
|
1182
1885
|
* @category instances
|
|
1183
1886
|
* @since 2.0.0
|
|
1184
1887
|
*/
|
|
1185
1888
|
export declare const getEquivalence: <A>(isEquivalent: Equivalence.Equivalence<A>) => Equivalence.Equivalence<ReadonlyArray<A>>;
|
|
1186
1889
|
/**
|
|
1187
|
-
*
|
|
1890
|
+
* Performs a side-effect for each element of the `Iterable`.
|
|
1891
|
+
*
|
|
1892
|
+
* @example
|
|
1893
|
+
* import { Array } from "effect"
|
|
1894
|
+
*
|
|
1895
|
+
* const numbers = [1, 2, 3]
|
|
1896
|
+
* Array.forEach(numbers, n => console.log(n)) // 1, 2, 3
|
|
1188
1897
|
*
|
|
1189
1898
|
* @since 2.0.0
|
|
1190
1899
|
*/
|
|
@@ -1196,6 +1905,13 @@ export declare const forEach: {
|
|
|
1196
1905
|
* Remove duplicates from an `Iterable` using the provided `isEquivalent` function,
|
|
1197
1906
|
* preserving the order of the first occurrence of each element.
|
|
1198
1907
|
*
|
|
1908
|
+
* @example
|
|
1909
|
+
* import { Array } from "effect"
|
|
1910
|
+
*
|
|
1911
|
+
* const numbers = [1, 2, 2, 3, 3, 3]
|
|
1912
|
+
* const unique = Array.dedupeWith(numbers, (a, b) => a === b)
|
|
1913
|
+
* assert.deepStrictEqual(unique, [1, 2, 3])
|
|
1914
|
+
*
|
|
1199
1915
|
* @since 2.0.0
|
|
1200
1916
|
*/
|
|
1201
1917
|
export declare const dedupeWith: {
|
|
@@ -1213,6 +1929,13 @@ export declare const dedupe: <S extends readonly [any, ...any[]] | Iterable<any>
|
|
|
1213
1929
|
/**
|
|
1214
1930
|
* Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.
|
|
1215
1931
|
*
|
|
1932
|
+
* @example
|
|
1933
|
+
* import { Array } from "effect"
|
|
1934
|
+
*
|
|
1935
|
+
* const numbers = [1, 1, 2, 2, 3, 3]
|
|
1936
|
+
* const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b)
|
|
1937
|
+
* assert.deepStrictEqual(unique, [1, 2, 3])
|
|
1938
|
+
*
|
|
1216
1939
|
* @since 2.0.0
|
|
1217
1940
|
*/
|
|
1218
1941
|
export declare const dedupeAdjacentWith: {
|
|
@@ -1222,12 +1945,26 @@ export declare const dedupeAdjacentWith: {
|
|
|
1222
1945
|
/**
|
|
1223
1946
|
* Deduplicates adjacent elements that are identical.
|
|
1224
1947
|
*
|
|
1948
|
+
* @example
|
|
1949
|
+
* import { Array } from "effect"
|
|
1950
|
+
*
|
|
1951
|
+
* const numbers = [1, 1, 2, 2, 3, 3]
|
|
1952
|
+
* const unique = Array.dedupeAdjacent(numbers)
|
|
1953
|
+
* assert.deepStrictEqual(unique, [1, 2, 3])
|
|
1954
|
+
*
|
|
1225
1955
|
* @since 2.0.0
|
|
1226
1956
|
*/
|
|
1227
1957
|
export declare const dedupeAdjacent: <A>(self: Iterable<A>) => Array<A>;
|
|
1228
1958
|
/**
|
|
1229
1959
|
* Joins the elements together with "sep" in the middle.
|
|
1230
1960
|
*
|
|
1961
|
+
* @example
|
|
1962
|
+
* import { Array } from "effect"
|
|
1963
|
+
*
|
|
1964
|
+
* const strings = ["a", "b", "c"]
|
|
1965
|
+
* const joined = Array.join(strings, "-")
|
|
1966
|
+
* assert.deepStrictEqual(joined, "a-b-c")
|
|
1967
|
+
*
|
|
1231
1968
|
* @since 2.0.0
|
|
1232
1969
|
* @category folding
|
|
1233
1970
|
*/
|
|
@@ -1238,6 +1975,13 @@ export declare const join: {
|
|
|
1238
1975
|
/**
|
|
1239
1976
|
* Statefully maps over the chunk, producing new elements of type `B`.
|
|
1240
1977
|
*
|
|
1978
|
+
* @example
|
|
1979
|
+
* import { Array } from "effect"
|
|
1980
|
+
*
|
|
1981
|
+
* const numbers = [1, 2, 3]
|
|
1982
|
+
* const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n])
|
|
1983
|
+
* assert.deepStrictEqual(result, [6, [1, 3, 6]])
|
|
1984
|
+
*
|
|
1241
1985
|
* @since 2.0.0
|
|
1242
1986
|
* @category folding
|
|
1243
1987
|
*/
|
|
@@ -1248,6 +1992,14 @@ export declare const mapAccum: {
|
|
|
1248
1992
|
/**
|
|
1249
1993
|
* Zips this chunk crosswise with the specified chunk using the specified combiner.
|
|
1250
1994
|
*
|
|
1995
|
+
* @example
|
|
1996
|
+
* import { Array } from "effect"
|
|
1997
|
+
*
|
|
1998
|
+
* const array1 = [1, 2]
|
|
1999
|
+
* const array2 = ["a", "b"]
|
|
2000
|
+
* const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)
|
|
2001
|
+
* assert.deepStrictEqual(product, ["1-a", "1-b", "2-a", "2-b"])
|
|
2002
|
+
*
|
|
1251
2003
|
* @since 2.0.0
|
|
1252
2004
|
* @category elements
|
|
1253
2005
|
*/
|
|
@@ -1258,6 +2010,14 @@ export declare const cartesianWith: {
|
|
|
1258
2010
|
/**
|
|
1259
2011
|
* Zips this chunk crosswise with the specified chunk.
|
|
1260
2012
|
*
|
|
2013
|
+
* @example
|
|
2014
|
+
* import { Array } from "effect"
|
|
2015
|
+
*
|
|
2016
|
+
* const array1 = [1, 2]
|
|
2017
|
+
* const array2 = ["a", "b"]
|
|
2018
|
+
* const product = Array.cartesian(array1, array2)
|
|
2019
|
+
* assert.deepStrictEqual(product, [[1, "a"], [1, "b"], [2, "a"], [2, "b"]])
|
|
2020
|
+
*
|
|
1261
2021
|
* @since 2.0.0
|
|
1262
2022
|
* @category elements
|
|
1263
2023
|
*/
|