effect 3.13.8 → 3.13.9
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 +460 -431
- package/dist/cjs/Array.js.map +1 -1
- package/dist/cjs/BigDecimal.js +31 -89
- package/dist/cjs/BigDecimal.js.map +1 -1
- package/dist/cjs/BigInt.js +27 -71
- package/dist/cjs/BigInt.js.map +1 -1
- package/dist/cjs/Boolean.js +12 -10
- package/dist/cjs/Boolean.js.map +1 -1
- package/dist/cjs/Brand.js +2 -0
- package/dist/cjs/Brand.js.map +1 -1
- package/dist/cjs/Channel.js +0 -2
- package/dist/cjs/Channel.js.map +1 -1
- package/dist/cjs/Chunk.js +4 -0
- package/dist/cjs/Chunk.js.map +1 -1
- package/dist/cjs/Config.js +0 -5
- package/dist/cjs/Config.js.map +1 -1
- package/dist/cjs/Context.js +14 -24
- package/dist/cjs/Context.js.map +1 -1
- package/dist/cjs/Cron.js +11 -25
- package/dist/cjs/Cron.js.map +1 -1
- package/dist/cjs/Data.js +6 -0
- package/dist/cjs/Data.js.map +1 -1
- package/dist/cjs/DateTime.js +2 -0
- package/dist/cjs/DateTime.js.map +1 -1
- package/dist/cjs/Duration.js +2 -2
- package/dist/cjs/Effect.js +122 -53
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/Either.js +21 -25
- package/dist/cjs/Either.js.map +1 -1
- package/dist/cjs/Encoding.js +1 -1
- package/dist/cjs/Equivalence.js +1 -1
- package/dist/cjs/Function.js +21 -24
- package/dist/cjs/Function.js.map +1 -1
- package/dist/cjs/HashMap.js +0 -3
- package/dist/cjs/HashMap.js.map +1 -1
- package/dist/cjs/Iterable.js +9 -2
- package/dist/cjs/Iterable.js.map +1 -1
- package/dist/cjs/List.js +2 -0
- package/dist/cjs/List.js.map +1 -1
- package/dist/cjs/Logger.js +0 -2
- package/dist/cjs/Logger.js.map +1 -1
- package/dist/cjs/Mailbox.js +1 -0
- package/dist/cjs/Mailbox.js.map +1 -1
- package/dist/cjs/ManagedRuntime.js +0 -2
- package/dist/cjs/ManagedRuntime.js.map +1 -1
- package/dist/cjs/Metric.js +6 -12
- package/dist/cjs/Metric.js.map +1 -1
- package/dist/cjs/Number.js +22 -61
- package/dist/cjs/Number.js.map +1 -1
- package/dist/cjs/Option.js +5 -0
- package/dist/cjs/Option.js.map +1 -1
- package/dist/cjs/Order.js +1 -0
- package/dist/cjs/Order.js.map +1 -1
- package/dist/cjs/Ordering.js +2 -7
- package/dist/cjs/Ordering.js.map +1 -1
- package/dist/cjs/Pool.js +1 -1
- package/dist/cjs/Predicate.js +36 -77
- package/dist/cjs/Predicate.js.map +1 -1
- package/dist/cjs/Random.js +1 -2
- package/dist/cjs/Random.js.map +1 -1
- package/dist/cjs/RcMap.js +5 -2
- package/dist/cjs/RcMap.js.map +1 -1
- package/dist/cjs/Record.js +28 -107
- package/dist/cjs/Record.js.map +1 -1
- package/dist/cjs/Redacted.js +3 -0
- package/dist/cjs/Redacted.js.map +1 -1
- package/dist/cjs/RegExp.js +2 -2
- package/dist/cjs/RegExp.js.map +1 -1
- package/dist/cjs/STM.js +3 -5
- package/dist/cjs/STM.js.map +1 -1
- package/dist/cjs/Schedule.js +2 -2
- package/dist/cjs/Schema.js +14 -13
- package/dist/cjs/Schema.js.map +1 -1
- package/dist/cjs/SchemaAST.js +0 -2
- package/dist/cjs/SchemaAST.js.map +1 -1
- package/dist/cjs/Sink.js +14 -10
- package/dist/cjs/Sink.js.map +1 -1
- package/dist/cjs/Stream.js +24 -25
- package/dist/cjs/Stream.js.map +1 -1
- package/dist/cjs/String.js +31 -2
- package/dist/cjs/String.js.map +1 -1
- package/dist/cjs/Struct.js +6 -0
- package/dist/cjs/Struct.js.map +1 -1
- package/dist/cjs/Symbol.js +1 -2
- package/dist/cjs/Symbol.js.map +1 -1
- package/dist/cjs/TestClock.js.map +1 -1
- package/dist/cjs/Trie.js +28 -0
- package/dist/cjs/Trie.js.map +1 -1
- package/dist/cjs/Tuple.js +9 -24
- package/dist/cjs/Tuple.js.map +1 -1
- package/dist/cjs/internal/matcher.js +1 -1
- package/dist/cjs/internal/matcher.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Array.d.ts +1235 -1188
- package/dist/dts/Array.d.ts.map +1 -1
- package/dist/dts/BigDecimal.d.ts +61 -189
- package/dist/dts/BigDecimal.d.ts.map +1 -1
- package/dist/dts/BigInt.d.ts +57 -165
- package/dist/dts/BigInt.d.ts.map +1 -1
- package/dist/dts/Boolean.d.ts +28 -18
- package/dist/dts/Boolean.d.ts.map +1 -1
- package/dist/dts/Brand.d.ts +3 -3
- package/dist/dts/Brand.d.ts.map +1 -1
- package/dist/dts/Channel.d.ts +0 -6
- package/dist/dts/Channel.d.ts.map +1 -1
- package/dist/dts/Chunk.d.ts +15 -0
- package/dist/dts/Chunk.d.ts.map +1 -1
- package/dist/dts/Config.d.ts +0 -5
- package/dist/dts/Config.d.ts.map +1 -1
- package/dist/dts/Context.d.ts +26 -54
- package/dist/dts/Context.d.ts.map +1 -1
- package/dist/dts/Cron.d.ts +9 -23
- package/dist/dts/Cron.d.ts.map +1 -1
- package/dist/dts/Data.d.ts +8 -0
- package/dist/dts/Data.d.ts.map +1 -1
- package/dist/dts/DateTime.d.ts +6 -0
- package/dist/dts/DateTime.d.ts.map +1 -1
- package/dist/dts/Duration.d.ts +2 -2
- package/dist/dts/Effect.d.ts +153 -71
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/Either.d.ts +44 -57
- package/dist/dts/Either.d.ts.map +1 -1
- package/dist/dts/Encoding.d.ts +1 -1
- package/dist/dts/Equivalence.d.ts +1 -1
- package/dist/dts/Function.d.ts +55 -59
- package/dist/dts/Function.d.ts.map +1 -1
- package/dist/dts/HashMap.d.ts +0 -9
- package/dist/dts/HashMap.d.ts.map +1 -1
- package/dist/dts/Iterable.d.ts +13 -2
- package/dist/dts/Iterable.d.ts.map +1 -1
- package/dist/dts/List.d.ts +10 -0
- package/dist/dts/List.d.ts.map +1 -1
- package/dist/dts/Logger.d.ts +0 -6
- package/dist/dts/Logger.d.ts.map +1 -1
- package/dist/dts/Mailbox.d.ts +1 -0
- package/dist/dts/Mailbox.d.ts.map +1 -1
- package/dist/dts/ManagedRuntime.d.ts +0 -2
- package/dist/dts/ManagedRuntime.d.ts.map +1 -1
- package/dist/dts/Metric.d.ts +14 -20
- package/dist/dts/Metric.d.ts.map +1 -1
- package/dist/dts/Micro.d.ts +1 -1
- package/dist/dts/Number.d.ts +52 -155
- package/dist/dts/Number.d.ts.map +1 -1
- package/dist/dts/Option.d.ts +12 -0
- package/dist/dts/Option.d.ts.map +1 -1
- package/dist/dts/Order.d.ts +1 -0
- package/dist/dts/Order.d.ts.map +1 -1
- package/dist/dts/Ordering.d.ts +4 -17
- package/dist/dts/Ordering.d.ts.map +1 -1
- package/dist/dts/Pool.d.ts +1 -1
- package/dist/dts/Predicate.d.ts +56 -133
- package/dist/dts/Predicate.d.ts.map +1 -1
- package/dist/dts/Random.d.ts +1 -2
- package/dist/dts/Random.d.ts.map +1 -1
- package/dist/dts/RcMap.d.ts +15 -6
- package/dist/dts/RcMap.d.ts.map +1 -1
- package/dist/dts/Record.d.ts +68 -279
- package/dist/dts/Record.d.ts.map +1 -1
- package/dist/dts/Redacted.d.ts +3 -0
- package/dist/dts/Redacted.d.ts.map +1 -1
- package/dist/dts/RegExp.d.ts +2 -2
- package/dist/dts/RegExp.d.ts.map +1 -1
- package/dist/dts/STM.d.ts +5 -7
- package/dist/dts/STM.d.ts.map +1 -1
- package/dist/dts/Schedule.d.ts +7 -7
- package/dist/dts/Schema.d.ts +31 -25
- package/dist/dts/Schema.d.ts.map +1 -1
- package/dist/dts/SchemaAST.d.ts +0 -2
- package/dist/dts/SchemaAST.d.ts.map +1 -1
- package/dist/dts/Sink.d.ts +14 -10
- package/dist/dts/Sink.d.ts.map +1 -1
- package/dist/dts/Stream.d.ts +58 -62
- package/dist/dts/Stream.d.ts.map +1 -1
- package/dist/dts/String.d.ts +47 -2
- package/dist/dts/String.d.ts.map +1 -1
- package/dist/dts/Struct.d.ts +12 -0
- package/dist/dts/Struct.d.ts.map +1 -1
- package/dist/dts/Symbol.d.ts +1 -2
- package/dist/dts/Symbol.d.ts.map +1 -1
- package/dist/dts/TestClock.d.ts +2 -1
- package/dist/dts/TestClock.d.ts.map +1 -1
- package/dist/dts/Trie.d.ts +66 -0
- package/dist/dts/Trie.d.ts.map +1 -1
- package/dist/dts/Tuple.d.ts +21 -62
- package/dist/dts/Tuple.d.ts.map +1 -1
- package/dist/dts/Utils.d.ts +8 -8
- package/dist/esm/Array.js +474 -442
- package/dist/esm/Array.js.map +1 -1
- package/dist/esm/BigDecimal.js +31 -89
- package/dist/esm/BigDecimal.js.map +1 -1
- package/dist/esm/BigInt.js +27 -71
- package/dist/esm/BigInt.js.map +1 -1
- package/dist/esm/Boolean.js +12 -10
- package/dist/esm/Boolean.js.map +1 -1
- package/dist/esm/Brand.js +2 -0
- package/dist/esm/Brand.js.map +1 -1
- package/dist/esm/Channel.js +0 -2
- package/dist/esm/Channel.js.map +1 -1
- package/dist/esm/Chunk.js +4 -0
- package/dist/esm/Chunk.js.map +1 -1
- package/dist/esm/Config.js +0 -5
- package/dist/esm/Config.js.map +1 -1
- package/dist/esm/Context.js +14 -24
- package/dist/esm/Context.js.map +1 -1
- package/dist/esm/Cron.js +11 -25
- package/dist/esm/Cron.js.map +1 -1
- package/dist/esm/Data.js +7 -0
- package/dist/esm/Data.js.map +1 -1
- package/dist/esm/DateTime.js +2 -0
- package/dist/esm/DateTime.js.map +1 -1
- package/dist/esm/Duration.js +2 -2
- package/dist/esm/Effect.js +123 -53
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/Either.js +22 -25
- package/dist/esm/Either.js.map +1 -1
- package/dist/esm/Encoding.js +1 -1
- package/dist/esm/Equivalence.js +1 -1
- package/dist/esm/Function.js +21 -24
- package/dist/esm/Function.js.map +1 -1
- package/dist/esm/HashMap.js +0 -3
- package/dist/esm/HashMap.js.map +1 -1
- package/dist/esm/Iterable.js +9 -2
- package/dist/esm/Iterable.js.map +1 -1
- package/dist/esm/List.js +2 -0
- package/dist/esm/List.js.map +1 -1
- package/dist/esm/Logger.js +0 -2
- package/dist/esm/Logger.js.map +1 -1
- package/dist/esm/Mailbox.js +1 -0
- package/dist/esm/Mailbox.js.map +1 -1
- package/dist/esm/ManagedRuntime.js +0 -2
- package/dist/esm/ManagedRuntime.js.map +1 -1
- package/dist/esm/Metric.js +6 -12
- package/dist/esm/Metric.js.map +1 -1
- package/dist/esm/Micro.js +1 -1
- package/dist/esm/Number.js +22 -61
- package/dist/esm/Number.js.map +1 -1
- package/dist/esm/Option.js +6 -0
- package/dist/esm/Option.js.map +1 -1
- package/dist/esm/Order.js +1 -0
- package/dist/esm/Order.js.map +1 -1
- package/dist/esm/Ordering.js +2 -7
- package/dist/esm/Ordering.js.map +1 -1
- package/dist/esm/Pool.js +1 -1
- package/dist/esm/Predicate.js +36 -77
- package/dist/esm/Predicate.js.map +1 -1
- package/dist/esm/Random.js +1 -2
- package/dist/esm/Random.js.map +1 -1
- package/dist/esm/RcMap.js +5 -2
- package/dist/esm/RcMap.js.map +1 -1
- package/dist/esm/Record.js +28 -107
- package/dist/esm/Record.js.map +1 -1
- package/dist/esm/Redacted.js +3 -0
- package/dist/esm/Redacted.js.map +1 -1
- package/dist/esm/RegExp.js +2 -2
- package/dist/esm/RegExp.js.map +1 -1
- package/dist/esm/STM.js +3 -5
- package/dist/esm/STM.js.map +1 -1
- package/dist/esm/Schedule.js +2 -2
- package/dist/esm/Schema.js +14 -13
- package/dist/esm/Schema.js.map +1 -1
- package/dist/esm/SchemaAST.js +0 -2
- package/dist/esm/SchemaAST.js.map +1 -1
- package/dist/esm/Sink.js +14 -10
- package/dist/esm/Sink.js.map +1 -1
- package/dist/esm/Stream.js +25 -25
- package/dist/esm/Stream.js.map +1 -1
- package/dist/esm/String.js +31 -2
- package/dist/esm/String.js.map +1 -1
- package/dist/esm/Struct.js +6 -0
- package/dist/esm/Struct.js.map +1 -1
- package/dist/esm/Symbol.js +1 -2
- package/dist/esm/Symbol.js.map +1 -1
- package/dist/esm/TestClock.js.map +1 -1
- package/dist/esm/Trie.js +28 -0
- package/dist/esm/Trie.js.map +1 -1
- package/dist/esm/Tuple.js +11 -30
- package/dist/esm/Tuple.js.map +1 -1
- package/dist/esm/internal/matcher.js +1 -1
- package/dist/esm/internal/matcher.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Array.ts +1235 -1188
- package/src/BigDecimal.ts +61 -189
- package/src/BigInt.ts +57 -165
- package/src/Boolean.ts +28 -18
- package/src/Brand.ts +3 -3
- package/src/Channel.ts +0 -6
- package/src/Chunk.ts +16 -0
- package/src/Config.ts +0 -5
- package/src/Context.ts +26 -54
- package/src/Cron.ts +11 -25
- package/src/Data.ts +8 -0
- package/src/DateTime.ts +6 -0
- package/src/Duration.ts +2 -2
- package/src/Effect.ts +153 -71
- package/src/Either.ts +45 -58
- package/src/Encoding.ts +1 -1
- package/src/Equivalence.ts +1 -1
- package/src/Function.ts +55 -59
- package/src/HashMap.ts +0 -9
- package/src/Iterable.ts +13 -2
- package/src/List.ts +12 -0
- package/src/Logger.ts +0 -6
- package/src/Mailbox.ts +1 -0
- package/src/ManagedRuntime.ts +0 -2
- package/src/Metric.ts +14 -20
- package/src/Micro.ts +1 -1
- package/src/Number.ts +52 -155
- package/src/Option.ts +12 -0
- package/src/Order.ts +1 -0
- package/src/Ordering.ts +4 -17
- package/src/Pool.ts +1 -1
- package/src/Predicate.ts +56 -133
- package/src/Random.ts +1 -2
- package/src/RcMap.ts +15 -6
- package/src/Record.ts +68 -279
- package/src/Redacted.ts +3 -0
- package/src/RegExp.ts +2 -2
- package/src/STM.ts +5 -7
- package/src/Schedule.ts +7 -7
- package/src/Schema.ts +31 -25
- package/src/SchemaAST.ts +0 -2
- package/src/Sink.ts +14 -10
- package/src/Stream.ts +56 -61
- package/src/String.ts +47 -2
- package/src/Struct.ts +12 -0
- package/src/Symbol.ts +1 -2
- package/src/TestClock.ts +2 -1
- package/src/Trie.ts +66 -0
- package/src/Tuple.ts +21 -62
- package/src/Utils.ts +8 -8
- package/src/internal/matcher.ts +1 -1
- package/src/internal/version.ts +1 -1
package/dist/esm/Array.js
CHANGED
|
@@ -18,12 +18,13 @@ import * as Tuple from "./Tuple.js";
|
|
|
18
18
|
/**
|
|
19
19
|
* Builds a `NonEmptyArray` from an non-empty collection of elements.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
21
|
+
* **Example**
|
|
22
|
+
*
|
|
22
23
|
* ```ts
|
|
23
24
|
* import { Array } from "effect"
|
|
24
25
|
*
|
|
25
26
|
* const result = Array.make(1, 2, 3)
|
|
26
|
-
*
|
|
27
|
+
* console.log(result) // [1, 2, 3]
|
|
27
28
|
* ```
|
|
28
29
|
*
|
|
29
30
|
* @category constructors
|
|
@@ -33,12 +34,13 @@ export const make = (...elements) => elements;
|
|
|
33
34
|
/**
|
|
34
35
|
* Creates a new `Array` of the specified length.
|
|
35
36
|
*
|
|
36
|
-
*
|
|
37
|
+
* **Example**
|
|
38
|
+
*
|
|
37
39
|
* ```ts
|
|
38
40
|
* import { Array } from "effect"
|
|
39
41
|
*
|
|
40
42
|
* const result = Array.allocate<number>(3)
|
|
41
|
-
*
|
|
43
|
+
* console.log(result) // [ <3 empty items> ]
|
|
42
44
|
* ```
|
|
43
45
|
*
|
|
44
46
|
* @category constructors
|
|
@@ -50,11 +52,13 @@ export const allocate = n => new Array(n);
|
|
|
50
52
|
*
|
|
51
53
|
* **Note**. `n` is normalized to an integer >= 1.
|
|
52
54
|
*
|
|
53
|
-
*
|
|
55
|
+
* **Example**
|
|
56
|
+
*
|
|
54
57
|
* ```ts
|
|
55
58
|
* import { makeBy } from "effect/Array"
|
|
56
59
|
*
|
|
57
|
-
*
|
|
60
|
+
* const result = makeBy(5, n => n * 2)
|
|
61
|
+
* console.log(result) // [0, 2, 4, 6, 8]
|
|
58
62
|
* ```
|
|
59
63
|
*
|
|
60
64
|
* @category constructors
|
|
@@ -71,11 +75,13 @@ export const makeBy = /*#__PURE__*/dual(2, (n, f) => {
|
|
|
71
75
|
/**
|
|
72
76
|
* Return a `NonEmptyArray` containing a range of integers, including both endpoints.
|
|
73
77
|
*
|
|
74
|
-
*
|
|
78
|
+
* **Example**
|
|
79
|
+
*
|
|
75
80
|
* ```ts
|
|
76
81
|
* import { range } from "effect/Array"
|
|
77
82
|
*
|
|
78
|
-
*
|
|
83
|
+
* const result = range(1, 3)
|
|
84
|
+
* console.log(result) // [1, 2, 3]
|
|
79
85
|
* ```
|
|
80
86
|
*
|
|
81
87
|
* @category constructors
|
|
@@ -87,11 +93,13 @@ export const range = (start, end) => start <= end ? makeBy(end - start + 1, i =>
|
|
|
87
93
|
*
|
|
88
94
|
* **Note**. `n` is normalized to an integer >= 1.
|
|
89
95
|
*
|
|
90
|
-
*
|
|
96
|
+
* **Example**
|
|
97
|
+
*
|
|
91
98
|
* ```ts
|
|
92
99
|
* import { Array } from "effect"
|
|
93
100
|
*
|
|
94
|
-
*
|
|
101
|
+
* const result = Array.replicate("a", 3)
|
|
102
|
+
* console.log(result) // ["a", "a", "a"]
|
|
95
103
|
* ```
|
|
96
104
|
*
|
|
97
105
|
* @category constructors
|
|
@@ -103,13 +111,13 @@ export const replicate = /*#__PURE__*/dual(2, (a, n) => makeBy(n, () => a));
|
|
|
103
111
|
* If the input is already an array, it returns the input as-is.
|
|
104
112
|
* Otherwise, it converts the iterable collection to an array.
|
|
105
113
|
*
|
|
106
|
-
*
|
|
114
|
+
* **Example**
|
|
115
|
+
*
|
|
107
116
|
* ```ts
|
|
108
117
|
* import { Array } from "effect"
|
|
109
118
|
*
|
|
110
|
-
* const
|
|
111
|
-
*
|
|
112
|
-
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
119
|
+
* const result = Array.fromIterable(new Set([1, 2, 3]))
|
|
120
|
+
* console.log(result) // [1, 2, 3]
|
|
113
121
|
* ```
|
|
114
122
|
*
|
|
115
123
|
* @category constructors
|
|
@@ -119,13 +127,14 @@ export const fromIterable = collection => Array.isArray(collection) ? collection
|
|
|
119
127
|
/**
|
|
120
128
|
* Creates a new `Array` from a value that might not be an iterable.
|
|
121
129
|
*
|
|
122
|
-
*
|
|
130
|
+
* **Example**
|
|
131
|
+
*
|
|
123
132
|
* ```ts
|
|
124
133
|
* import { Array } from "effect"
|
|
125
134
|
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
135
|
+
* console.log(Array.ensure("a")) // ["a"]
|
|
136
|
+
* console.log(Array.ensure(["a"])) // ["a"]
|
|
137
|
+
* console.log(Array.ensure(["a", "b", "c"])) // ["a", "b", "c"]
|
|
129
138
|
* ```
|
|
130
139
|
*
|
|
131
140
|
* @category constructors
|
|
@@ -135,14 +144,13 @@ export const ensure = self => Array.isArray(self) ? self : [self];
|
|
|
135
144
|
/**
|
|
136
145
|
* Takes a record and returns an array of tuples containing its keys and values.
|
|
137
146
|
*
|
|
138
|
-
*
|
|
147
|
+
* **Example**
|
|
139
148
|
*
|
|
140
|
-
* @example
|
|
141
149
|
* ```ts
|
|
142
150
|
* import { Array } from "effect"
|
|
143
151
|
*
|
|
144
|
-
* const
|
|
145
|
-
*
|
|
152
|
+
* const result = Array.fromRecord({ a: 1, b: 2, c: 3 })
|
|
153
|
+
* console.log(result) // [["a", 1], ["b", 2], ["c", 3]]
|
|
146
154
|
* ```
|
|
147
155
|
*
|
|
148
156
|
* @category conversions
|
|
@@ -152,12 +160,13 @@ export const fromRecord = Record.toEntries;
|
|
|
152
160
|
/**
|
|
153
161
|
* Converts an `Option` to an array.
|
|
154
162
|
*
|
|
155
|
-
*
|
|
163
|
+
* **Example**
|
|
164
|
+
*
|
|
156
165
|
* ```ts
|
|
157
166
|
* import { Array, Option } from "effect"
|
|
158
167
|
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
168
|
+
* console.log(Array.fromOption(Option.some(1))) // [1]
|
|
169
|
+
* console.log(Array.fromOption(Option.none())) // []
|
|
161
170
|
* ```
|
|
162
171
|
*
|
|
163
172
|
* @category conversions
|
|
@@ -167,7 +176,8 @@ export const fromOption = O.toArray;
|
|
|
167
176
|
/**
|
|
168
177
|
* Matches the elements of an array, applying functions to cases of empty and non-empty arrays.
|
|
169
178
|
*
|
|
170
|
-
*
|
|
179
|
+
* **Example**
|
|
180
|
+
*
|
|
171
181
|
* ```ts
|
|
172
182
|
* import { Array } from "effect"
|
|
173
183
|
*
|
|
@@ -175,8 +185,8 @@ export const fromOption = O.toArray;
|
|
|
175
185
|
* onEmpty: () => "empty",
|
|
176
186
|
* onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`
|
|
177
187
|
* })
|
|
178
|
-
*
|
|
179
|
-
*
|
|
188
|
+
* console.log(match([])) // "empty"
|
|
189
|
+
* console.log(match([1, 2, 3])) // "head: 1, tail: 2"
|
|
180
190
|
* ```
|
|
181
191
|
*
|
|
182
192
|
* @category pattern matching
|
|
@@ -189,7 +199,8 @@ export const match = /*#__PURE__*/dual(2, (self, {
|
|
|
189
199
|
/**
|
|
190
200
|
* Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.
|
|
191
201
|
*
|
|
192
|
-
*
|
|
202
|
+
* **Example**
|
|
203
|
+
*
|
|
193
204
|
* ```ts
|
|
194
205
|
* import { Array } from "effect"
|
|
195
206
|
*
|
|
@@ -197,8 +208,8 @@ export const match = /*#__PURE__*/dual(2, (self, {
|
|
|
197
208
|
* onEmpty: () => "empty",
|
|
198
209
|
* onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`
|
|
199
210
|
* })
|
|
200
|
-
*
|
|
201
|
-
*
|
|
211
|
+
* console.log(matchLeft([])) // "empty"
|
|
212
|
+
* console.log(matchLeft([1, 2, 3])) // "head: 1, tail: 2"
|
|
202
213
|
* ```
|
|
203
214
|
*
|
|
204
215
|
* @category pattern matching
|
|
@@ -211,7 +222,8 @@ export const matchLeft = /*#__PURE__*/dual(2, (self, {
|
|
|
211
222
|
/**
|
|
212
223
|
* Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.
|
|
213
224
|
*
|
|
214
|
-
*
|
|
225
|
+
* **Example**
|
|
226
|
+
*
|
|
215
227
|
* ```ts
|
|
216
228
|
* import { Array } from "effect"
|
|
217
229
|
*
|
|
@@ -219,8 +231,8 @@ export const matchLeft = /*#__PURE__*/dual(2, (self, {
|
|
|
219
231
|
* onEmpty: () => "empty",
|
|
220
232
|
* onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`
|
|
221
233
|
* })
|
|
222
|
-
*
|
|
223
|
-
*
|
|
234
|
+
* console.log(matchRight([])) // "empty"
|
|
235
|
+
* console.log(matchRight([1, 2, 3])) // "init: 2, last: 3"
|
|
224
236
|
* ```
|
|
225
237
|
*
|
|
226
238
|
* @category pattern matching
|
|
@@ -233,13 +245,13 @@ export const matchRight = /*#__PURE__*/dual(2, (self, {
|
|
|
233
245
|
/**
|
|
234
246
|
* Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.
|
|
235
247
|
*
|
|
236
|
-
*
|
|
248
|
+
* **Example**
|
|
249
|
+
*
|
|
237
250
|
* ```ts
|
|
238
251
|
* import { Array } from "effect"
|
|
239
252
|
*
|
|
240
|
-
* const
|
|
241
|
-
*
|
|
242
|
-
* assert.deepStrictEqual(result, [1, 2, 3, 4]);
|
|
253
|
+
* const result = Array.prepend([2, 3, 4], 1)
|
|
254
|
+
* console.log(result) // [1, 2, 3, 4]
|
|
243
255
|
* ```
|
|
244
256
|
*
|
|
245
257
|
* @category concatenating
|
|
@@ -250,14 +262,13 @@ export const prepend = /*#__PURE__*/dual(2, (self, head) => [head, ...self]);
|
|
|
250
262
|
* Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).
|
|
251
263
|
* If either array is non-empty, the result is also a non-empty array.
|
|
252
264
|
*
|
|
253
|
-
*
|
|
265
|
+
* **Example**
|
|
266
|
+
*
|
|
254
267
|
* ```ts
|
|
255
268
|
* import { Array } from "effect"
|
|
256
269
|
*
|
|
257
|
-
* const
|
|
258
|
-
*
|
|
259
|
-
* const result = Array.prependAll(array, prefix);
|
|
260
|
-
* assert.deepStrictEqual(result, [0, 1, 2, 3]);
|
|
270
|
+
* const result = Array.prependAll([2, 3], [0, 1])
|
|
271
|
+
* console.log(result) // [0, 1, 2, 3]
|
|
261
272
|
* ```
|
|
262
273
|
*
|
|
263
274
|
* @category concatenating
|
|
@@ -267,13 +278,13 @@ export const prependAll = /*#__PURE__*/dual(2, (self, that) => fromIterable(that
|
|
|
267
278
|
/**
|
|
268
279
|
* Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.
|
|
269
280
|
*
|
|
270
|
-
*
|
|
281
|
+
* **Example**
|
|
282
|
+
*
|
|
271
283
|
* ```ts
|
|
272
284
|
* import { Array } from "effect"
|
|
273
285
|
*
|
|
274
|
-
* const
|
|
275
|
-
*
|
|
276
|
-
* assert.deepStrictEqual(result, [1, 2, 3, 4]);
|
|
286
|
+
* const result = Array.append([1, 2, 3], 4);
|
|
287
|
+
* console.log(result) // [1, 2, 3, 4]
|
|
277
288
|
* ```
|
|
278
289
|
*
|
|
279
290
|
* @category concatenating
|
|
@@ -293,13 +304,13 @@ export const appendAll = /*#__PURE__*/dual(2, (self, that) => fromIterable(self)
|
|
|
293
304
|
* each intermediate result in an array. Useful for tracking the progression of
|
|
294
305
|
* a value through a series of transformations.
|
|
295
306
|
*
|
|
296
|
-
*
|
|
307
|
+
* **Example**
|
|
308
|
+
*
|
|
297
309
|
* ```ts
|
|
298
310
|
* import { Array } from "effect";
|
|
299
311
|
*
|
|
300
|
-
* const
|
|
301
|
-
*
|
|
302
|
-
* assert.deepStrictEqual(result, [0, 1, 3, 6, 10])
|
|
312
|
+
* const result = Array.scan([1, 2, 3, 4], 0, (acc, value) => acc + value)
|
|
313
|
+
* console.log(result) // [0, 1, 3, 6, 10]
|
|
303
314
|
*
|
|
304
315
|
* // Explanation:
|
|
305
316
|
* // This function starts with the initial value (0 in this case)
|
|
@@ -325,13 +336,13 @@ export const scan = /*#__PURE__*/dual(3, (self, b, f) => {
|
|
|
325
336
|
* each intermediate result in an array. Useful for tracking the progression of
|
|
326
337
|
* a value through a series of transformations.
|
|
327
338
|
*
|
|
328
|
-
*
|
|
339
|
+
* **Example**
|
|
340
|
+
*
|
|
329
341
|
* ```ts
|
|
330
342
|
* import { Array } from "effect";
|
|
331
343
|
*
|
|
332
|
-
* const
|
|
333
|
-
*
|
|
334
|
-
* assert.deepStrictEqual(result, [10, 9, 7, 4, 0])
|
|
344
|
+
* const result = Array.scanRight([1, 2, 3, 4], 0, (acc, value) => acc + value)
|
|
345
|
+
* console.log(result) // [10, 9, 7, 4, 0]
|
|
335
346
|
* ```
|
|
336
347
|
*
|
|
337
348
|
* @category folding
|
|
@@ -349,14 +360,13 @@ export const scanRight = /*#__PURE__*/dual(3, (self, b, f) => {
|
|
|
349
360
|
/**
|
|
350
361
|
* Determine if `unknown` is an Array.
|
|
351
362
|
*
|
|
352
|
-
*
|
|
363
|
+
* **Example**
|
|
353
364
|
*
|
|
354
|
-
* @example
|
|
355
365
|
* ```ts
|
|
356
|
-
* import {
|
|
366
|
+
* import { Array } from "effect"
|
|
357
367
|
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
368
|
+
* console.log(Array.isArray(null)) // false
|
|
369
|
+
* console.log(Array.isArray([1, 2, 3])) // true
|
|
360
370
|
* ```
|
|
361
371
|
*
|
|
362
372
|
* @category guards
|
|
@@ -366,14 +376,13 @@ export const isArray = Array.isArray;
|
|
|
366
376
|
/**
|
|
367
377
|
* Determine if an `Array` is empty narrowing down the type to `[]`.
|
|
368
378
|
*
|
|
369
|
-
*
|
|
379
|
+
* **Example**
|
|
370
380
|
*
|
|
371
|
-
* @example
|
|
372
381
|
* ```ts
|
|
373
|
-
* import {
|
|
382
|
+
* import { Array } from "effect"
|
|
374
383
|
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
384
|
+
* console.log(Array.isEmptyArray([])) // true
|
|
385
|
+
* console.log(Array.isEmptyArray([1, 2, 3])) // false
|
|
377
386
|
* ```
|
|
378
387
|
*
|
|
379
388
|
* @category guards
|
|
@@ -383,14 +392,13 @@ export const isEmptyArray = self => self.length === 0;
|
|
|
383
392
|
/**
|
|
384
393
|
* Determine if a `ReadonlyArray` is empty narrowing down the type to `readonly []`.
|
|
385
394
|
*
|
|
386
|
-
*
|
|
395
|
+
* **Example**
|
|
387
396
|
*
|
|
388
|
-
* @example
|
|
389
397
|
* ```ts
|
|
390
|
-
* import {
|
|
398
|
+
* import { Array } from "effect"
|
|
391
399
|
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
400
|
+
* console.log(Array.isEmptyReadonlyArray([])) // true
|
|
401
|
+
* console.log(Array.isEmptyReadonlyArray([1, 2, 3])) // false
|
|
394
402
|
* ```
|
|
395
403
|
*
|
|
396
404
|
* @category guards
|
|
@@ -402,14 +410,13 @@ export const isEmptyReadonlyArray = isEmptyArray;
|
|
|
402
410
|
*
|
|
403
411
|
* An `Array` is considered to be a `NonEmptyArray` if it contains at least one element.
|
|
404
412
|
*
|
|
405
|
-
*
|
|
413
|
+
* **Example**
|
|
406
414
|
*
|
|
407
|
-
* @example
|
|
408
415
|
* ```ts
|
|
409
|
-
* import {
|
|
416
|
+
* import { Array } from "effect"
|
|
410
417
|
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
418
|
+
* console.log(Array.isNonEmptyArray([])) // false
|
|
419
|
+
* console.log(Array.isNonEmptyArray([1, 2, 3])) // true
|
|
413
420
|
* ```
|
|
414
421
|
*
|
|
415
422
|
* @category guards
|
|
@@ -421,14 +428,13 @@ export const isNonEmptyArray = readonlyArray.isNonEmptyArray;
|
|
|
421
428
|
*
|
|
422
429
|
* A `ReadonlyArray` is considered to be a `NonEmptyReadonlyArray` if it contains at least one element.
|
|
423
430
|
*
|
|
424
|
-
*
|
|
431
|
+
* **Example**
|
|
425
432
|
*
|
|
426
|
-
* @example
|
|
427
433
|
* ```ts
|
|
428
|
-
* import {
|
|
434
|
+
* import { Array } from "effect"
|
|
429
435
|
*
|
|
430
|
-
*
|
|
431
|
-
*
|
|
436
|
+
* console.log(Array.isNonEmptyReadonlyArray([])) // false
|
|
437
|
+
* console.log(Array.isNonEmptyReadonlyArray([1, 2, 3])) // true
|
|
432
438
|
* ```
|
|
433
439
|
*
|
|
434
440
|
* @category guards
|
|
@@ -470,12 +476,13 @@ export const unsafeGet = /*#__PURE__*/dual(2, (self, index) => {
|
|
|
470
476
|
/**
|
|
471
477
|
* Return a tuple containing the first element, and a new `Array` of the remaining elements, if any.
|
|
472
478
|
*
|
|
473
|
-
*
|
|
479
|
+
* **Example**
|
|
480
|
+
*
|
|
474
481
|
* ```ts
|
|
475
482
|
* import { Array } from "effect";
|
|
476
483
|
*
|
|
477
484
|
* const result = Array.unprepend([1, 2, 3, 4])
|
|
478
|
-
*
|
|
485
|
+
* console.log(result) // [1, [2, 3, 4]]
|
|
479
486
|
* ```
|
|
480
487
|
*
|
|
481
488
|
* @category splitting
|
|
@@ -485,12 +492,13 @@ export const unprepend = self => [headNonEmpty(self), tailNonEmpty(self)];
|
|
|
485
492
|
/**
|
|
486
493
|
* Return a tuple containing a copy of the `NonEmptyReadonlyArray` without its last element, and that last element.
|
|
487
494
|
*
|
|
488
|
-
*
|
|
495
|
+
* **Example**
|
|
496
|
+
*
|
|
489
497
|
* ```ts
|
|
490
498
|
* import { Array } from "effect";
|
|
491
499
|
*
|
|
492
500
|
* const result = Array.unappend([1, 2, 3, 4])
|
|
493
|
-
*
|
|
501
|
+
* console.log(result) // [[1, 2, 3], 4]
|
|
494
502
|
* ```
|
|
495
503
|
*
|
|
496
504
|
* @category splitting
|
|
@@ -507,12 +515,13 @@ export const head = /*#__PURE__*/get(0);
|
|
|
507
515
|
/**
|
|
508
516
|
* Get the first element of a non empty array.
|
|
509
517
|
*
|
|
510
|
-
*
|
|
518
|
+
* **Example**
|
|
519
|
+
*
|
|
511
520
|
* ```ts
|
|
512
521
|
* import { Array } from "effect"
|
|
513
522
|
*
|
|
514
523
|
* const result = Array.headNonEmpty([1, 2, 3, 4])
|
|
515
|
-
*
|
|
524
|
+
* console.log(result) // 1
|
|
516
525
|
* ```
|
|
517
526
|
*
|
|
518
527
|
* @category getters
|
|
@@ -529,12 +538,13 @@ export const last = self => isNonEmptyReadonlyArray(self) ? O.some(lastNonEmpty(
|
|
|
529
538
|
/**
|
|
530
539
|
* Get the last element of a non empty array.
|
|
531
540
|
*
|
|
532
|
-
*
|
|
541
|
+
* **Example**
|
|
542
|
+
*
|
|
533
543
|
* ```ts
|
|
534
544
|
* import { Array } from "effect"
|
|
535
545
|
*
|
|
536
546
|
* const result = Array.lastNonEmpty([1, 2, 3, 4])
|
|
537
|
-
*
|
|
547
|
+
* console.log(result) // 4
|
|
538
548
|
* ```
|
|
539
549
|
*
|
|
540
550
|
* @category getters
|
|
@@ -554,12 +564,13 @@ export const tail = self => {
|
|
|
554
564
|
/**
|
|
555
565
|
* Get all but the first element of a `NonEmptyReadonlyArray`.
|
|
556
566
|
*
|
|
557
|
-
*
|
|
567
|
+
* **Example**
|
|
568
|
+
*
|
|
558
569
|
* ```ts
|
|
559
570
|
* import { Array } from "effect"
|
|
560
571
|
*
|
|
561
572
|
* const result = Array.tailNonEmpty([1, 2, 3, 4])
|
|
562
|
-
*
|
|
573
|
+
* console.log(result) // [2, 3, 4]
|
|
563
574
|
* ```
|
|
564
575
|
*
|
|
565
576
|
* @category getters
|
|
@@ -579,12 +590,13 @@ export const init = self => {
|
|
|
579
590
|
/**
|
|
580
591
|
* Get all but the last element of a non empty array, creating a new array.
|
|
581
592
|
*
|
|
582
|
-
*
|
|
593
|
+
* **Example**
|
|
594
|
+
*
|
|
583
595
|
* ```ts
|
|
584
596
|
* import { Array } from "effect"
|
|
585
597
|
*
|
|
586
598
|
* const result = Array.initNonEmpty([1, 2, 3, 4])
|
|
587
|
-
*
|
|
599
|
+
* console.log(result) // [1, 2, 3]
|
|
588
600
|
* ```
|
|
589
601
|
*
|
|
590
602
|
* @category getters
|
|
@@ -596,13 +608,13 @@ export const initNonEmpty = self => self.slice(0, -1);
|
|
|
596
608
|
*
|
|
597
609
|
* **Note**. `n` is normalized to a non negative integer.
|
|
598
610
|
*
|
|
599
|
-
*
|
|
611
|
+
* **Example**
|
|
612
|
+
*
|
|
600
613
|
* ```ts
|
|
601
614
|
* import { Array } from "effect"
|
|
602
615
|
*
|
|
603
|
-
* const
|
|
604
|
-
*
|
|
605
|
-
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
616
|
+
* const result = Array.take([1, 2, 3, 4, 5], 3)
|
|
617
|
+
* console.log(result) // [1, 2, 3]
|
|
606
618
|
* ```
|
|
607
619
|
*
|
|
608
620
|
* @category getters
|
|
@@ -617,13 +629,13 @@ export const take = /*#__PURE__*/dual(2, (self, n) => {
|
|
|
617
629
|
*
|
|
618
630
|
* **Note**. `n` is normalized to a non negative integer.
|
|
619
631
|
*
|
|
620
|
-
*
|
|
632
|
+
* **Example**
|
|
633
|
+
*
|
|
621
634
|
* ```ts
|
|
622
635
|
* import { Array } from "effect"
|
|
623
636
|
*
|
|
624
|
-
* const
|
|
625
|
-
*
|
|
626
|
-
* assert.deepStrictEqual(result, [3, 4, 5])
|
|
637
|
+
* const result = Array.takeRight([1, 2, 3, 4, 5], 3)
|
|
638
|
+
* console.log(result) // [3, 4, 5]
|
|
627
639
|
* ```
|
|
628
640
|
*
|
|
629
641
|
* @category getters
|
|
@@ -637,13 +649,13 @@ export const takeRight = /*#__PURE__*/dual(2, (self, n) => {
|
|
|
637
649
|
/**
|
|
638
650
|
* Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.
|
|
639
651
|
*
|
|
640
|
-
*
|
|
652
|
+
* **Example**
|
|
653
|
+
*
|
|
641
654
|
* ```ts
|
|
642
655
|
* import { Array } from "effect"
|
|
643
656
|
*
|
|
644
|
-
* const
|
|
645
|
-
*
|
|
646
|
-
* assert.deepStrictEqual(result, [1, 3, 2])
|
|
657
|
+
* const result = Array.takeWhile([1, 3, 2, 4, 1, 2], x => x < 4)
|
|
658
|
+
* console.log(result) // [1, 3, 2]
|
|
647
659
|
*
|
|
648
660
|
* // Explanation:
|
|
649
661
|
* // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.
|
|
@@ -692,13 +704,13 @@ export const span = /*#__PURE__*/dual(2, (self, predicate) => splitAt(self, span
|
|
|
692
704
|
*
|
|
693
705
|
* **Note**. `n` is normalized to a non negative integer.
|
|
694
706
|
*
|
|
695
|
-
*
|
|
707
|
+
* **Example**
|
|
708
|
+
*
|
|
696
709
|
* ```ts
|
|
697
710
|
* import { Array } from "effect"
|
|
698
711
|
*
|
|
699
|
-
* const
|
|
700
|
-
*
|
|
701
|
-
* assert.deepStrictEqual(result, [3, 4, 5])
|
|
712
|
+
* const result = Array.drop([1, 2, 3, 4, 5], 2)
|
|
713
|
+
* console.log(result) // [3, 4, 5]
|
|
702
714
|
* ```
|
|
703
715
|
*
|
|
704
716
|
* @category getters
|
|
@@ -713,13 +725,13 @@ export const drop = /*#__PURE__*/dual(2, (self, n) => {
|
|
|
713
725
|
*
|
|
714
726
|
* **Note**. `n` is normalized to a non negative integer.
|
|
715
727
|
*
|
|
716
|
-
*
|
|
728
|
+
* **Example**
|
|
729
|
+
*
|
|
717
730
|
* ```ts
|
|
718
731
|
* import { Array } from "effect"
|
|
719
732
|
*
|
|
720
|
-
* const
|
|
721
|
-
*
|
|
722
|
-
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
733
|
+
* const result = Array.dropRight([1, 2, 3, 4, 5], 2)
|
|
734
|
+
* console.log(result) // [1, 2, 3]
|
|
723
735
|
* ```
|
|
724
736
|
*
|
|
725
737
|
* @category getters
|
|
@@ -732,13 +744,13 @@ export const dropRight = /*#__PURE__*/dual(2, (self, n) => {
|
|
|
732
744
|
/**
|
|
733
745
|
* Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.
|
|
734
746
|
*
|
|
735
|
-
*
|
|
747
|
+
* **Example**
|
|
748
|
+
*
|
|
736
749
|
* ```ts
|
|
737
750
|
* import { Array } from "effect"
|
|
738
751
|
*
|
|
739
|
-
* const
|
|
740
|
-
*
|
|
741
|
-
* assert.deepStrictEqual(result, [4, 5])
|
|
752
|
+
* const result = Array.dropWhile([1, 2, 3, 4, 5], x => x < 4)
|
|
753
|
+
* console.log(result) // [4, 5]
|
|
742
754
|
* ```
|
|
743
755
|
*
|
|
744
756
|
* @category getters
|
|
@@ -748,13 +760,13 @@ export const dropWhile = /*#__PURE__*/dual(2, (self, predicate) => fromIterable(
|
|
|
748
760
|
/**
|
|
749
761
|
* Return the first index for which a predicate holds.
|
|
750
762
|
*
|
|
751
|
-
*
|
|
763
|
+
* **Example**
|
|
764
|
+
*
|
|
752
765
|
* ```ts
|
|
753
|
-
* import { Array
|
|
766
|
+
* import { Array } from "effect"
|
|
754
767
|
*
|
|
755
|
-
* const
|
|
756
|
-
*
|
|
757
|
-
* assert.deepStrictEqual(result, Option.some(2))
|
|
768
|
+
* const result = Array.findFirstIndex([5, 3, 8, 9], x => x > 5)
|
|
769
|
+
* console.log(result) // Option.some(2)
|
|
758
770
|
* ```
|
|
759
771
|
*
|
|
760
772
|
* @category elements
|
|
@@ -773,13 +785,13 @@ export const findFirstIndex = /*#__PURE__*/dual(2, (self, predicate) => {
|
|
|
773
785
|
/**
|
|
774
786
|
* Return the last index for which a predicate holds.
|
|
775
787
|
*
|
|
776
|
-
*
|
|
788
|
+
* **Example**
|
|
789
|
+
*
|
|
777
790
|
* ```ts
|
|
778
|
-
* import { Array
|
|
791
|
+
* import { Array } from "effect"
|
|
779
792
|
*
|
|
780
|
-
* const
|
|
781
|
-
*
|
|
782
|
-
* assert.deepStrictEqual(result, Option.some(1))
|
|
793
|
+
* const result = Array.findLastIndex([1, 3, 8, 9], x => x < 5)
|
|
794
|
+
* console.log(result) // Option.some(1)
|
|
783
795
|
* ```
|
|
784
796
|
*
|
|
785
797
|
* @category elements
|
|
@@ -798,13 +810,13 @@ export const findLastIndex = /*#__PURE__*/dual(2, (self, predicate) => {
|
|
|
798
810
|
* Returns the first element that satisfies the specified
|
|
799
811
|
* predicate, or `None` if no such element exists.
|
|
800
812
|
*
|
|
801
|
-
*
|
|
813
|
+
* **Example**
|
|
814
|
+
*
|
|
802
815
|
* ```ts
|
|
803
|
-
* import { Array
|
|
816
|
+
* import { Array } from "effect"
|
|
804
817
|
*
|
|
805
|
-
* const
|
|
806
|
-
*
|
|
807
|
-
* assert.deepStrictEqual(result, Option.some(4))
|
|
818
|
+
* const result = Array.findFirst([1, 2, 3, 4, 5], x => x > 3)
|
|
819
|
+
* console.log(result) // Option.some(4)
|
|
808
820
|
* ```
|
|
809
821
|
*
|
|
810
822
|
* @category elements
|
|
@@ -815,13 +827,13 @@ export const findFirst = EffectIterable.findFirst;
|
|
|
815
827
|
* Finds the last element in an iterable collection that satisfies the given predicate or refinement.
|
|
816
828
|
* Returns an `Option` containing the found element, or `Option.none` if no element matches.
|
|
817
829
|
*
|
|
818
|
-
*
|
|
830
|
+
* **Example**
|
|
831
|
+
*
|
|
819
832
|
* ```ts
|
|
820
|
-
* import { Array
|
|
833
|
+
* import { Array } from "effect"
|
|
821
834
|
*
|
|
822
|
-
* const
|
|
823
|
-
*
|
|
824
|
-
* assert.deepStrictEqual(result, Option.some(4))
|
|
835
|
+
* const result = Array.findLast([1, 2, 3, 4, 5], n => n % 2 === 0)
|
|
836
|
+
* console.log(result) // Option.some(4)
|
|
825
837
|
* ```
|
|
826
838
|
*
|
|
827
839
|
* @category elements
|
|
@@ -848,13 +860,13 @@ export const findLast = /*#__PURE__*/dual(2, (self, f) => {
|
|
|
848
860
|
* Insert an element at the specified index, creating a new `NonEmptyArray`,
|
|
849
861
|
* or return `None` if the index is out of bounds.
|
|
850
862
|
*
|
|
851
|
-
*
|
|
863
|
+
* **Example**
|
|
864
|
+
*
|
|
852
865
|
* ```ts
|
|
853
|
-
* import { Array
|
|
866
|
+
* import { Array } from "effect"
|
|
854
867
|
*
|
|
855
|
-
* const
|
|
856
|
-
*
|
|
857
|
-
* assert.deepStrictEqual(result, Option.some(['a', 'b', 'c', 'd', 'e']))
|
|
868
|
+
* const result = Array.insertAt(['a', 'b', 'c', 'e'], 3, 'd')
|
|
869
|
+
* console.log(result) // Option.some(['a', 'b', 'c', 'd', 'e'])
|
|
858
870
|
* ```
|
|
859
871
|
*
|
|
860
872
|
* @since 2.0.0
|
|
@@ -872,13 +884,13 @@ export const insertAt = /*#__PURE__*/dual(3, (self, i, b) => {
|
|
|
872
884
|
* Change the element at the specified index, creating a new `Array`,
|
|
873
885
|
* or return a copy of the input if the index is out of bounds.
|
|
874
886
|
*
|
|
875
|
-
*
|
|
887
|
+
* **Example**
|
|
888
|
+
*
|
|
876
889
|
* ```ts
|
|
877
890
|
* import { Array } from "effect"
|
|
878
891
|
*
|
|
879
|
-
* const
|
|
880
|
-
*
|
|
881
|
-
* assert.deepStrictEqual(result, ['a', 'z', 'c', 'd'])
|
|
892
|
+
* const result = Array.replace(['a', 'b', 'c', 'd'], 1, 'z')
|
|
893
|
+
* console.log(result) // ['a', 'z', 'c', 'd']
|
|
882
894
|
* ```
|
|
883
895
|
*
|
|
884
896
|
* @since 2.0.0
|
|
@@ -887,13 +899,13 @@ export const replace = /*#__PURE__*/dual(3, (self, i, b) => modify(self, i, () =
|
|
|
887
899
|
/**
|
|
888
900
|
* Replaces an element in an array with the given value, returning an option of the updated array.
|
|
889
901
|
*
|
|
890
|
-
*
|
|
902
|
+
* **Example**
|
|
903
|
+
*
|
|
891
904
|
* ```ts
|
|
892
|
-
* import { Array
|
|
905
|
+
* import { Array } from "effect"
|
|
893
906
|
*
|
|
894
|
-
* const
|
|
895
|
-
*
|
|
896
|
-
* assert.deepStrictEqual(result, Option.some([1, 4, 3]))
|
|
907
|
+
* const result = Array.replaceOption([1, 2, 3], 1, 4)
|
|
908
|
+
* console.log(result) // Option.some([1, 4, 3])
|
|
897
909
|
* ```
|
|
898
910
|
*
|
|
899
911
|
* @since 2.0.0
|
|
@@ -903,13 +915,13 @@ export const replaceOption = /*#__PURE__*/dual(3, (self, i, b) => modifyOption(s
|
|
|
903
915
|
* Apply a function to the element at the specified index, creating a new `Array`,
|
|
904
916
|
* or return a copy of the input if the index is out of bounds.
|
|
905
917
|
*
|
|
906
|
-
*
|
|
918
|
+
* **Example**
|
|
919
|
+
*
|
|
907
920
|
* ```ts
|
|
908
921
|
* import { Array } from "effect"
|
|
909
922
|
*
|
|
910
|
-
* const
|
|
911
|
-
*
|
|
912
|
-
* assert.deepStrictEqual(result, [1, 2, 6, 4])
|
|
923
|
+
* const result = Array.modify([1, 2, 3, 4], 2, (n) => n * 2)
|
|
924
|
+
* console.log(result) // [1, 2, 6, 4]
|
|
913
925
|
* ```
|
|
914
926
|
*
|
|
915
927
|
* @since 2.0.0
|
|
@@ -919,16 +931,17 @@ export const modify = /*#__PURE__*/dual(3, (self, i, f) => O.getOrElse(modifyOpt
|
|
|
919
931
|
* Apply a function to the element at the specified index, creating a new `Array`,
|
|
920
932
|
* or return `None` if the index is out of bounds.
|
|
921
933
|
*
|
|
922
|
-
*
|
|
934
|
+
* **Example**
|
|
935
|
+
*
|
|
923
936
|
* ```ts
|
|
924
|
-
* import { Array
|
|
937
|
+
* import { Array } from "effect"
|
|
925
938
|
*
|
|
926
|
-
* const
|
|
927
|
-
* const result = Array.modifyOption(
|
|
928
|
-
*
|
|
939
|
+
* const input = [1, 2, 3, 4]
|
|
940
|
+
* const result = Array.modifyOption(input, 2, (n) => n * 2)
|
|
941
|
+
* console.log(result) // Option.some([1, 2, 6, 4])
|
|
929
942
|
*
|
|
930
|
-
* const outOfBoundsResult = Array.modifyOption(
|
|
931
|
-
*
|
|
943
|
+
* const outOfBoundsResult = Array.modifyOption(input, 5, (n) => n * 2)
|
|
944
|
+
* console.log(outOfBoundsResult) // Option.none()
|
|
932
945
|
* ```
|
|
933
946
|
*
|
|
934
947
|
* @since 2.0.0
|
|
@@ -947,16 +960,17 @@ export const modifyOption = /*#__PURE__*/dual(3, (self, i, f) => {
|
|
|
947
960
|
* Delete the element at the specified index, creating a new `Array`,
|
|
948
961
|
* or return a copy of the input if the index is out of bounds.
|
|
949
962
|
*
|
|
950
|
-
*
|
|
963
|
+
* **Example**
|
|
964
|
+
*
|
|
951
965
|
* ```ts
|
|
952
966
|
* import { Array } from "effect"
|
|
953
967
|
*
|
|
954
|
-
* const
|
|
955
|
-
* const result = Array.remove(
|
|
956
|
-
*
|
|
968
|
+
* const input = [1, 2, 3, 4]
|
|
969
|
+
* const result = Array.remove(input, 2)
|
|
970
|
+
* console.log(result) // [1, 2, 4]
|
|
957
971
|
*
|
|
958
|
-
* const outOfBoundsResult = Array.remove(
|
|
959
|
-
*
|
|
972
|
+
* const outOfBoundsResult = Array.remove(input, 5)
|
|
973
|
+
* console.log(outOfBoundsResult) // [1, 2, 3, 4]
|
|
960
974
|
* ```
|
|
961
975
|
*
|
|
962
976
|
* @since 2.0.0
|
|
@@ -972,13 +986,13 @@ export const remove = /*#__PURE__*/dual(2, (self, i) => {
|
|
|
972
986
|
/**
|
|
973
987
|
* Reverse an `Iterable`, creating a new `Array`.
|
|
974
988
|
*
|
|
975
|
-
*
|
|
989
|
+
* **Example**
|
|
990
|
+
*
|
|
976
991
|
* ```ts
|
|
977
992
|
* import { Array } from "effect"
|
|
978
993
|
*
|
|
979
|
-
* const
|
|
980
|
-
*
|
|
981
|
-
* assert.deepStrictEqual(result, [4, 3, 2, 1])
|
|
994
|
+
* const result = Array.reverse([1, 2, 3, 4])
|
|
995
|
+
* console.log(result) // [4, 3, 2, 1]
|
|
982
996
|
* ```
|
|
983
997
|
*
|
|
984
998
|
* @category elements
|
|
@@ -1002,13 +1016,13 @@ export const sort = /*#__PURE__*/dual(2, (self, O) => {
|
|
|
1002
1016
|
* function transforms the elements into a value that can be compared, and the
|
|
1003
1017
|
* order defines how those values should be sorted.
|
|
1004
1018
|
*
|
|
1005
|
-
*
|
|
1019
|
+
* **Example**
|
|
1020
|
+
*
|
|
1006
1021
|
* ```ts
|
|
1007
1022
|
* import { Array, Order } from "effect"
|
|
1008
1023
|
*
|
|
1009
|
-
* const
|
|
1010
|
-
*
|
|
1011
|
-
* assert.deepStrictEqual(result, ["b", "cc", "aaa"])
|
|
1024
|
+
* const result = Array.sortWith(["aaa", "b", "cc"], (s) => s.length, Order.number)
|
|
1025
|
+
* console.log(result) // ["b", "cc", "aaa"]
|
|
1012
1026
|
*
|
|
1013
1027
|
* // Explanation:
|
|
1014
1028
|
* // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`
|
|
@@ -1025,9 +1039,10 @@ export const sortWith = /*#__PURE__*/dual(3, (self, f, order) => Array.from(self
|
|
|
1025
1039
|
* orders. The elements are compared using the first order in `orders`, then the
|
|
1026
1040
|
* second order if the first comparison is equal, and so on.
|
|
1027
1041
|
*
|
|
1028
|
-
*
|
|
1042
|
+
* **Example**
|
|
1043
|
+
*
|
|
1029
1044
|
* ```ts
|
|
1030
|
-
* import { Array, Order } from "effect"
|
|
1045
|
+
* import { Array, Order, pipe } from "effect"
|
|
1031
1046
|
*
|
|
1032
1047
|
* const users = [
|
|
1033
1048
|
* { name: "Alice", age: 30 },
|
|
@@ -1035,16 +1050,20 @@ export const sortWith = /*#__PURE__*/dual(3, (self, f, order) => Array.from(self
|
|
|
1035
1050
|
* { name: "Charlie", age: 30 }
|
|
1036
1051
|
* ]
|
|
1037
1052
|
*
|
|
1038
|
-
* const result =
|
|
1039
|
-
*
|
|
1040
|
-
*
|
|
1041
|
-
*
|
|
1053
|
+
* const result = pipe(
|
|
1054
|
+
* users,
|
|
1055
|
+
* Array.sortBy(
|
|
1056
|
+
* Order.mapInput(Order.number, (user: (typeof users)[number]) => user.age),
|
|
1057
|
+
* Order.mapInput(Order.string, (user: (typeof users)[number]) => user.name)
|
|
1058
|
+
* )
|
|
1059
|
+
* )
|
|
1042
1060
|
*
|
|
1043
|
-
*
|
|
1044
|
-
*
|
|
1045
|
-
* { name: "
|
|
1046
|
-
* { name: "
|
|
1047
|
-
*
|
|
1061
|
+
* console.log(result)
|
|
1062
|
+
* // [
|
|
1063
|
+
* // { name: "Bob", age: 25 },
|
|
1064
|
+
* // { name: "Alice", age: 30 },
|
|
1065
|
+
* // { name: "Charlie", age: 30 }
|
|
1066
|
+
* // ]
|
|
1048
1067
|
*
|
|
1049
1068
|
* // Explanation:
|
|
1050
1069
|
* // The array of users is sorted first by age in ascending order. When ages are equal,
|
|
@@ -1069,14 +1088,13 @@ export const sortBy = (...orders) => {
|
|
|
1069
1088
|
* If one input `Iterable` is short, excess elements of the
|
|
1070
1089
|
* longer `Iterable` are discarded.
|
|
1071
1090
|
*
|
|
1072
|
-
*
|
|
1091
|
+
* **Example**
|
|
1092
|
+
*
|
|
1073
1093
|
* ```ts
|
|
1074
1094
|
* import { Array } from "effect"
|
|
1075
1095
|
*
|
|
1076
|
-
* const
|
|
1077
|
-
*
|
|
1078
|
-
* const result = Array.zip(array1, array2)
|
|
1079
|
-
* assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])
|
|
1096
|
+
* const result = Array.zip([1, 2, 3], ['a', 'b'])
|
|
1097
|
+
* console.log(result) // [[1, 'a'], [2, 'b']]
|
|
1080
1098
|
* ```
|
|
1081
1099
|
*
|
|
1082
1100
|
* @category zipping
|
|
@@ -1087,14 +1105,13 @@ export const zip = /*#__PURE__*/dual(2, (self, that) => zipWith(self, that, Tupl
|
|
|
1087
1105
|
* Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one
|
|
1088
1106
|
* input `Iterable` is short, excess elements of the longer `Iterable` are discarded.
|
|
1089
1107
|
*
|
|
1090
|
-
*
|
|
1108
|
+
* **Example**
|
|
1109
|
+
*
|
|
1091
1110
|
* ```ts
|
|
1092
1111
|
* import { Array } from "effect"
|
|
1093
1112
|
*
|
|
1094
|
-
* const
|
|
1095
|
-
*
|
|
1096
|
-
* const result = Array.zipWith(array1, array2, (a, b) => a + b)
|
|
1097
|
-
* assert.deepStrictEqual(result, [5, 7, 9])
|
|
1113
|
+
* const result = Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)
|
|
1114
|
+
* console.log(result) // [5, 7, 9]
|
|
1098
1115
|
* ```
|
|
1099
1116
|
*
|
|
1100
1117
|
* @category zipping
|
|
@@ -1116,12 +1133,13 @@ export const zipWith = /*#__PURE__*/dual(3, (self, that, f) => {
|
|
|
1116
1133
|
/**
|
|
1117
1134
|
* This function is the inverse of `zip`. Takes an `Iterable` of pairs and return two corresponding `Array`s.
|
|
1118
1135
|
*
|
|
1119
|
-
*
|
|
1136
|
+
* **Example**
|
|
1137
|
+
*
|
|
1120
1138
|
* ```ts
|
|
1121
1139
|
* import { Array } from "effect"
|
|
1122
1140
|
*
|
|
1123
1141
|
* const result = Array.unzip([[1, "a"], [2, "b"], [3, "c"]])
|
|
1124
|
-
*
|
|
1142
|
+
* console.log(result) // [[1, 2, 3], ['a', 'b', 'c']]
|
|
1125
1143
|
* ```
|
|
1126
1144
|
*
|
|
1127
1145
|
* @since 2.0.0
|
|
@@ -1143,13 +1161,13 @@ export const unzip = self => {
|
|
|
1143
1161
|
* Places an element in between members of an `Iterable`.
|
|
1144
1162
|
* If the input is a non-empty array, the result is also a non-empty array.
|
|
1145
1163
|
*
|
|
1146
|
-
*
|
|
1164
|
+
* **Example**
|
|
1165
|
+
*
|
|
1147
1166
|
* ```ts
|
|
1148
1167
|
* import { Array } from "effect"
|
|
1149
1168
|
*
|
|
1150
|
-
* const
|
|
1151
|
-
*
|
|
1152
|
-
* assert.deepStrictEqual(result, [1, 0, 2, 0, 3])
|
|
1169
|
+
* const result = Array.intersperse([1, 2, 3], 0)
|
|
1170
|
+
* console.log(result) // [1, 0, 2, 0, 3]
|
|
1153
1171
|
* ```
|
|
1154
1172
|
*
|
|
1155
1173
|
* @since 2.0.0
|
|
@@ -1172,12 +1190,13 @@ export const intersperse = /*#__PURE__*/dual(2, (self, middle) => {
|
|
|
1172
1190
|
/**
|
|
1173
1191
|
* Apply a function to the head, creating a new `NonEmptyReadonlyArray`.
|
|
1174
1192
|
*
|
|
1175
|
-
*
|
|
1193
|
+
* **Example**
|
|
1194
|
+
*
|
|
1176
1195
|
* ```ts
|
|
1177
1196
|
* import { Array } from "effect"
|
|
1178
1197
|
*
|
|
1179
1198
|
* const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)
|
|
1180
|
-
*
|
|
1199
|
+
* console.log(result) // [10, 2, 3]
|
|
1181
1200
|
* ```
|
|
1182
1201
|
*
|
|
1183
1202
|
* @since 2.0.0
|
|
@@ -1186,12 +1205,13 @@ export const modifyNonEmptyHead = /*#__PURE__*/dual(2, (self, f) => [f(headNonEm
|
|
|
1186
1205
|
/**
|
|
1187
1206
|
* Change the head, creating a new `NonEmptyReadonlyArray`.
|
|
1188
1207
|
*
|
|
1189
|
-
*
|
|
1208
|
+
* **Example**
|
|
1209
|
+
*
|
|
1190
1210
|
* ```ts
|
|
1191
1211
|
* import { Array } from "effect"
|
|
1192
1212
|
*
|
|
1193
1213
|
* const result = Array.setNonEmptyHead([1, 2, 3], 10)
|
|
1194
|
-
*
|
|
1214
|
+
* console.log(result) // [10, 2, 3]
|
|
1195
1215
|
* ```
|
|
1196
1216
|
*
|
|
1197
1217
|
* @since 2.0.0
|
|
@@ -1200,12 +1220,13 @@ export const setNonEmptyHead = /*#__PURE__*/dual(2, (self, b) => modifyNonEmptyH
|
|
|
1200
1220
|
/**
|
|
1201
1221
|
* Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.
|
|
1202
1222
|
*
|
|
1203
|
-
*
|
|
1223
|
+
* **Example**
|
|
1224
|
+
*
|
|
1204
1225
|
* ```ts
|
|
1205
1226
|
* import { Array } from "effect"
|
|
1206
1227
|
*
|
|
1207
1228
|
* const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)
|
|
1208
|
-
*
|
|
1229
|
+
* console.log(result) // [1, 2, 6]
|
|
1209
1230
|
* ```
|
|
1210
1231
|
*
|
|
1211
1232
|
* @since 2.0.0
|
|
@@ -1214,12 +1235,13 @@ export const modifyNonEmptyLast = /*#__PURE__*/dual(2, (self, f) => append(initN
|
|
|
1214
1235
|
/**
|
|
1215
1236
|
* Change the last element, creating a new `NonEmptyReadonlyArray`.
|
|
1216
1237
|
*
|
|
1217
|
-
*
|
|
1238
|
+
* **Example**
|
|
1239
|
+
*
|
|
1218
1240
|
* ```ts
|
|
1219
1241
|
* import { Array } from "effect"
|
|
1220
1242
|
*
|
|
1221
1243
|
* const result = Array.setNonEmptyLast([1, 2, 3], 4)
|
|
1222
|
-
*
|
|
1244
|
+
* console.log(result) // [1, 2, 4]
|
|
1223
1245
|
* ```
|
|
1224
1246
|
*
|
|
1225
1247
|
* @since 2.0.0
|
|
@@ -1229,13 +1251,13 @@ export const setNonEmptyLast = /*#__PURE__*/dual(2, (self, b) => modifyNonEmptyL
|
|
|
1229
1251
|
* Rotate an `Iterable` by `n` steps.
|
|
1230
1252
|
* If the input is a non-empty array, the result is also a non-empty array.
|
|
1231
1253
|
*
|
|
1232
|
-
*
|
|
1254
|
+
* **Example**
|
|
1255
|
+
*
|
|
1233
1256
|
* ```ts
|
|
1234
1257
|
* import { Array } from "effect"
|
|
1235
1258
|
*
|
|
1236
|
-
* const
|
|
1237
|
-
*
|
|
1238
|
-
* assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])
|
|
1259
|
+
* const result = Array.rotate(['a', 'b', 'c', 'd'], 2)
|
|
1260
|
+
* console.log(result) // ['c', 'd', 'a', 'b']
|
|
1239
1261
|
* ```
|
|
1240
1262
|
*
|
|
1241
1263
|
* @since 2.0.0
|
|
@@ -1260,15 +1282,15 @@ export const rotate = /*#__PURE__*/dual(2, (self, n) => {
|
|
|
1260
1282
|
/**
|
|
1261
1283
|
* Returns a function that checks if a `ReadonlyArray` contains a given value using a provided `isEquivalent` function.
|
|
1262
1284
|
*
|
|
1263
|
-
*
|
|
1285
|
+
* **Example**
|
|
1286
|
+
*
|
|
1264
1287
|
* ```ts
|
|
1265
|
-
* import { Array } from "effect"
|
|
1288
|
+
* import { Array, pipe } from "effect"
|
|
1266
1289
|
*
|
|
1267
|
-
* const numbers = [1, 2, 3, 4]
|
|
1268
1290
|
* const isEquivalent = (a: number, b: number) => a === b
|
|
1269
1291
|
* const containsNumber = Array.containsWith(isEquivalent)
|
|
1270
|
-
* const result = containsNumber(3)
|
|
1271
|
-
*
|
|
1292
|
+
* const result = pipe([1, 2, 3, 4], containsNumber(3))
|
|
1293
|
+
* console.log(result) // true
|
|
1272
1294
|
* ```
|
|
1273
1295
|
*
|
|
1274
1296
|
* @category elements
|
|
@@ -1286,13 +1308,13 @@ const _equivalence = /*#__PURE__*/Equal.equivalence();
|
|
|
1286
1308
|
/**
|
|
1287
1309
|
* Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.
|
|
1288
1310
|
*
|
|
1289
|
-
*
|
|
1311
|
+
* **Example**
|
|
1312
|
+
*
|
|
1290
1313
|
* ```ts
|
|
1291
|
-
* import { Array } from "effect"
|
|
1314
|
+
* import { Array, pipe } from "effect"
|
|
1292
1315
|
*
|
|
1293
|
-
* const
|
|
1294
|
-
*
|
|
1295
|
-
* assert.deepStrictEqual(result, true)
|
|
1316
|
+
* const result = pipe(['a', 'b', 'c', 'd'], Array.contains('c'))
|
|
1317
|
+
* console.log(result) // true
|
|
1296
1318
|
* ```
|
|
1297
1319
|
*
|
|
1298
1320
|
* @category elements
|
|
@@ -1304,13 +1326,13 @@ export const contains = /*#__PURE__*/containsWith(_equivalence);
|
|
|
1304
1326
|
* `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a
|
|
1305
1327
|
* value and the rest of the `Array`.
|
|
1306
1328
|
*
|
|
1307
|
-
*
|
|
1329
|
+
* **Example**
|
|
1330
|
+
*
|
|
1308
1331
|
* ```ts
|
|
1309
1332
|
* import { Array } from "effect"
|
|
1310
1333
|
*
|
|
1311
|
-
* const
|
|
1312
|
-
*
|
|
1313
|
-
* assert.deepStrictEqual(result, [2, 4, 6, 8, 10])
|
|
1334
|
+
* const result = Array.chop([1, 2, 3, 4, 5], (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])
|
|
1335
|
+
* console.log(result) // [2, 4, 6, 8, 10]
|
|
1314
1336
|
*
|
|
1315
1337
|
* // Explanation:
|
|
1316
1338
|
* // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.
|
|
@@ -1339,13 +1361,13 @@ export const chop = /*#__PURE__*/dual(2, (self, f) => {
|
|
|
1339
1361
|
* Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.
|
|
1340
1362
|
* The value of `n` can be `0`.
|
|
1341
1363
|
*
|
|
1342
|
-
*
|
|
1364
|
+
* **Example**
|
|
1365
|
+
*
|
|
1343
1366
|
* ```ts
|
|
1344
1367
|
* import { Array } from "effect"
|
|
1345
1368
|
*
|
|
1346
|
-
* const
|
|
1347
|
-
*
|
|
1348
|
-
* assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])
|
|
1369
|
+
* const result = Array.splitAt([1, 2, 3, 4, 5], 3)
|
|
1370
|
+
* console.log(result) // [[1, 2, 3], [4, 5]]
|
|
1349
1371
|
* ```
|
|
1350
1372
|
*
|
|
1351
1373
|
* @category splitting
|
|
@@ -1366,12 +1388,13 @@ export const splitAt = /*#__PURE__*/dual(2, (self, n) => {
|
|
|
1366
1388
|
* Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.
|
|
1367
1389
|
* The value of `n` must be `>= 1`.
|
|
1368
1390
|
*
|
|
1369
|
-
*
|
|
1391
|
+
* **Example**
|
|
1392
|
+
*
|
|
1370
1393
|
* ```ts
|
|
1371
1394
|
* import { Array } from "effect"
|
|
1372
1395
|
*
|
|
1373
1396
|
* const result = Array.splitNonEmptyAt(["a", "b", "c", "d", "e"], 3)
|
|
1374
|
-
*
|
|
1397
|
+
* console.log(result) // [["a", "b", "c"], ["d", "e"]]
|
|
1375
1398
|
* ```
|
|
1376
1399
|
*
|
|
1377
1400
|
* @category splitting
|
|
@@ -1384,13 +1407,13 @@ export const splitNonEmptyAt = /*#__PURE__*/dual(2, (self, n) => {
|
|
|
1384
1407
|
/**
|
|
1385
1408
|
* Splits this iterable into `n` equally sized arrays.
|
|
1386
1409
|
*
|
|
1387
|
-
*
|
|
1410
|
+
* **Example**
|
|
1411
|
+
*
|
|
1388
1412
|
* ```ts
|
|
1389
1413
|
* import { Array } from "effect"
|
|
1390
1414
|
*
|
|
1391
|
-
* const
|
|
1392
|
-
*
|
|
1393
|
-
* assert.deepStrictEqual(result, [[1, 2, 3], [4, 5, 6], [7, 8]])
|
|
1415
|
+
* const result = Array.split([1, 2, 3, 4, 5, 6, 7, 8], 3)
|
|
1416
|
+
* console.log(result) // [[1, 2, 3], [4, 5, 6], [7, 8]]
|
|
1394
1417
|
* ```
|
|
1395
1418
|
*
|
|
1396
1419
|
* @since 2.0.0
|
|
@@ -1404,13 +1427,13 @@ export const split = /*#__PURE__*/dual(2, (self, n) => {
|
|
|
1404
1427
|
* Splits this iterable on the first element that matches this predicate.
|
|
1405
1428
|
* Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.
|
|
1406
1429
|
*
|
|
1407
|
-
*
|
|
1430
|
+
* **Example**
|
|
1431
|
+
*
|
|
1408
1432
|
* ```ts
|
|
1409
1433
|
* import { Array } from "effect"
|
|
1410
1434
|
*
|
|
1411
|
-
* const
|
|
1412
|
-
*
|
|
1413
|
-
* assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])
|
|
1435
|
+
* const result = Array.splitWhere([1, 2, 3, 4, 5], n => n > 3)
|
|
1436
|
+
* console.log(result) // [[1, 2, 3], [4, 5]]
|
|
1414
1437
|
* ```
|
|
1415
1438
|
*
|
|
1416
1439
|
* @category splitting
|
|
@@ -1420,13 +1443,13 @@ export const splitWhere = /*#__PURE__*/dual(2, (self, predicate) => span(self, (
|
|
|
1420
1443
|
/**
|
|
1421
1444
|
* Copies an array.
|
|
1422
1445
|
*
|
|
1423
|
-
*
|
|
1446
|
+
* **Example**
|
|
1447
|
+
*
|
|
1424
1448
|
* ```ts
|
|
1425
1449
|
* import { Array } from "effect"
|
|
1426
1450
|
*
|
|
1427
|
-
* const
|
|
1428
|
-
*
|
|
1429
|
-
* assert.deepStrictEqual(copy, [1, 2, 3])
|
|
1451
|
+
* const result = Array.copy([1, 2, 3])
|
|
1452
|
+
* console.log(result) // [1, 2, 3]
|
|
1430
1453
|
* ```
|
|
1431
1454
|
*
|
|
1432
1455
|
* @since 2.0.0
|
|
@@ -1438,13 +1461,13 @@ export const copy = self => self.slice();
|
|
|
1438
1461
|
* If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.
|
|
1439
1462
|
* If `n` is less than or equal to 0, the returned array will be an empty array.
|
|
1440
1463
|
*
|
|
1441
|
-
*
|
|
1464
|
+
* **Example**
|
|
1465
|
+
*
|
|
1442
1466
|
* ```ts
|
|
1443
1467
|
* import { Array } from "effect"
|
|
1444
1468
|
*
|
|
1445
|
-
* const
|
|
1446
|
-
*
|
|
1447
|
-
* assert.deepStrictEqual(result, [1, 2, 3, 0, 0, 0])
|
|
1469
|
+
* const result = Array.pad([1, 2, 3], 6, 0)
|
|
1470
|
+
* console.log(result) // [1, 2, 3, 0, 0, 0]
|
|
1448
1471
|
* ```
|
|
1449
1472
|
*
|
|
1450
1473
|
* @since 3.8.4
|
|
@@ -1460,19 +1483,19 @@ export const pad = /*#__PURE__*/dual(3, (self, n, fill) => {
|
|
|
1460
1483
|
* the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive
|
|
1461
1484
|
* definition of `chunksOf`; it satisfies the property that
|
|
1462
1485
|
*
|
|
1463
|
-
* ```ts
|
|
1486
|
+
* ```ts skip-type-checking
|
|
1464
1487
|
* chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))
|
|
1465
1488
|
* ```
|
|
1466
1489
|
*
|
|
1467
1490
|
* whenever `n` evenly divides the length of `self`.
|
|
1468
1491
|
*
|
|
1469
|
-
*
|
|
1492
|
+
* **Example**
|
|
1493
|
+
*
|
|
1470
1494
|
* ```ts
|
|
1471
1495
|
* import { Array } from "effect"
|
|
1472
1496
|
*
|
|
1473
|
-
* const
|
|
1474
|
-
*
|
|
1475
|
-
* assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])
|
|
1497
|
+
* const result = Array.chunksOf([1, 2, 3, 4, 5], 2)
|
|
1498
|
+
* console.log(result) // [[1, 2], [3, 4], [5]]
|
|
1476
1499
|
*
|
|
1477
1500
|
* // Explanation:
|
|
1478
1501
|
* // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.
|
|
@@ -1494,12 +1517,13 @@ export const chunksOf = /*#__PURE__*/dual(2, (self, n) => {
|
|
|
1494
1517
|
/**
|
|
1495
1518
|
* Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.
|
|
1496
1519
|
*
|
|
1497
|
-
*
|
|
1520
|
+
* **Example**
|
|
1521
|
+
*
|
|
1498
1522
|
* ```ts
|
|
1499
1523
|
* import { Array } from "effect"
|
|
1500
1524
|
*
|
|
1501
1525
|
* const result = Array.groupWith(["a", "a", "b", "b", "b", "c", "a"], (x, y) => x === y)
|
|
1502
|
-
*
|
|
1526
|
+
* console.log(result) // [["a", "a"], ["b", "b", "b"], ["c"], ["a"]]
|
|
1503
1527
|
* ```
|
|
1504
1528
|
*
|
|
1505
1529
|
* @category grouping
|
|
@@ -1522,12 +1546,13 @@ export const groupWith = /*#__PURE__*/dual(2, (self, isEquivalent) => chop(self,
|
|
|
1522
1546
|
/**
|
|
1523
1547
|
* Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s.
|
|
1524
1548
|
*
|
|
1525
|
-
*
|
|
1549
|
+
* **Example**
|
|
1550
|
+
*
|
|
1526
1551
|
* ```ts
|
|
1527
1552
|
* import { Array } from "effect"
|
|
1528
1553
|
*
|
|
1529
1554
|
* const result = Array.group([1, 1, 2, 2, 2, 3, 1])
|
|
1530
|
-
*
|
|
1555
|
+
* console.log(result) // [[1, 1], [2, 2, 2], [3], [1]]
|
|
1531
1556
|
* ```
|
|
1532
1557
|
*
|
|
1533
1558
|
* @category grouping
|
|
@@ -1538,7 +1563,8 @@ export const group = /*#__PURE__*/groupWith( /*#__PURE__*/Equal.equivalence());
|
|
|
1538
1563
|
* Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning
|
|
1539
1564
|
* function on each element, and grouping the results according to values returned
|
|
1540
1565
|
*
|
|
1541
|
-
*
|
|
1566
|
+
* **Example**
|
|
1567
|
+
*
|
|
1542
1568
|
* ```ts
|
|
1543
1569
|
* import { Array } from "effect"
|
|
1544
1570
|
*
|
|
@@ -1547,11 +1573,13 @@ export const group = /*#__PURE__*/groupWith( /*#__PURE__*/Equal.equivalence());
|
|
|
1547
1573
|
* { name: "Bob", group: "B" },
|
|
1548
1574
|
* { name: "Charlie", group: "A" }
|
|
1549
1575
|
* ]
|
|
1576
|
+
*
|
|
1550
1577
|
* const result = Array.groupBy(people, person => person.group)
|
|
1551
|
-
*
|
|
1552
|
-
*
|
|
1553
|
-
*
|
|
1554
|
-
* }
|
|
1578
|
+
* console.log(result)
|
|
1579
|
+
* // {
|
|
1580
|
+
* // A: [{ name: "Alice", group: "A" }, { name: "Charlie", group: "A" }],
|
|
1581
|
+
* // B: [{ name: "Bob", group: "B" }]
|
|
1582
|
+
* // }
|
|
1555
1583
|
* ```
|
|
1556
1584
|
*
|
|
1557
1585
|
* @category grouping
|
|
@@ -1572,14 +1600,13 @@ export const groupBy = /*#__PURE__*/dual(2, (self, f) => {
|
|
|
1572
1600
|
/**
|
|
1573
1601
|
* Calculates the union of two arrays using the provided equivalence relation.
|
|
1574
1602
|
*
|
|
1575
|
-
*
|
|
1603
|
+
* **Example**
|
|
1604
|
+
*
|
|
1576
1605
|
* ```ts
|
|
1577
1606
|
* import { Array } from "effect"
|
|
1578
1607
|
*
|
|
1579
|
-
* const
|
|
1580
|
-
*
|
|
1581
|
-
* const union = Array.unionWith(array1, array2, (a, b) => a === b)
|
|
1582
|
-
* assert.deepStrictEqual(union, [1, 2, 3])
|
|
1608
|
+
* const union = Array.unionWith([1, 2], [2, 3], (a, b) => a === b)
|
|
1609
|
+
* console.log(union) // [1, 2, 3]
|
|
1583
1610
|
* ```
|
|
1584
1611
|
*
|
|
1585
1612
|
* @since 2.0.0
|
|
@@ -1599,14 +1626,13 @@ export const unionWith = /*#__PURE__*/dual(3, (self, that, isEquivalent) => {
|
|
|
1599
1626
|
/**
|
|
1600
1627
|
* Creates a union of two arrays, removing duplicates.
|
|
1601
1628
|
*
|
|
1602
|
-
*
|
|
1629
|
+
* **Example**
|
|
1630
|
+
*
|
|
1603
1631
|
* ```ts
|
|
1604
1632
|
* import { Array } from "effect"
|
|
1605
1633
|
*
|
|
1606
|
-
* const
|
|
1607
|
-
*
|
|
1608
|
-
* const result = Array.union(array1, array2)
|
|
1609
|
-
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
1634
|
+
* const result = Array.union([1, 2], [2, 3])
|
|
1635
|
+
* console.log(result) // [1, 2, 3]
|
|
1610
1636
|
* ```
|
|
1611
1637
|
*
|
|
1612
1638
|
* @since 2.0.0
|
|
@@ -1616,7 +1642,8 @@ export const union = /*#__PURE__*/dual(2, (self, that) => unionWith(self, that,
|
|
|
1616
1642
|
* Creates an `Array` of unique values that are included in all given `Iterable`s using the provided `isEquivalent` function.
|
|
1617
1643
|
* The order and references of result values are determined by the first `Iterable`.
|
|
1618
1644
|
*
|
|
1619
|
-
*
|
|
1645
|
+
* **Example**
|
|
1646
|
+
*
|
|
1620
1647
|
* ```ts
|
|
1621
1648
|
* import { Array } from "effect"
|
|
1622
1649
|
*
|
|
@@ -1624,7 +1651,7 @@ export const union = /*#__PURE__*/dual(2, (self, that) => unionWith(self, that,
|
|
|
1624
1651
|
* const array2 = [{ id: 3 }, { id: 4 }, { id: 1 }]
|
|
1625
1652
|
* const isEquivalent = (a: { id: number }, b: { id: number }) => a.id === b.id
|
|
1626
1653
|
* const result = Array.intersectionWith(isEquivalent)(array2)(array1)
|
|
1627
|
-
*
|
|
1654
|
+
* console.log(result) // [{ id: 1 }, { id: 3 }]
|
|
1628
1655
|
* ```
|
|
1629
1656
|
*
|
|
1630
1657
|
* @since 2.0.0
|
|
@@ -1637,14 +1664,13 @@ export const intersectionWith = isEquivalent => {
|
|
|
1637
1664
|
* Creates an `Array` of unique values that are included in all given `Iterable`s.
|
|
1638
1665
|
* The order and references of result values are determined by the first `Iterable`.
|
|
1639
1666
|
*
|
|
1640
|
-
*
|
|
1667
|
+
* **Example**
|
|
1668
|
+
*
|
|
1641
1669
|
* ```ts
|
|
1642
1670
|
* import { Array } from "effect"
|
|
1643
1671
|
*
|
|
1644
|
-
* const
|
|
1645
|
-
*
|
|
1646
|
-
* const result = Array.intersection(array1, array2)
|
|
1647
|
-
* assert.deepStrictEqual(result, [1, 3])
|
|
1672
|
+
* const result = Array.intersection([1, 2, 3], [3, 4, 1])
|
|
1673
|
+
* console.log(result) // [1, 3]
|
|
1648
1674
|
* ```
|
|
1649
1675
|
*
|
|
1650
1676
|
* @since 2.0.0
|
|
@@ -1654,14 +1680,15 @@ export const intersection = /*#__PURE__*/intersectionWith(_equivalence);
|
|
|
1654
1680
|
* Creates a `Array` of values not included in the other given `Iterable` using the provided `isEquivalent` function.
|
|
1655
1681
|
* The order and references of result values are determined by the first `Iterable`.
|
|
1656
1682
|
*
|
|
1657
|
-
*
|
|
1683
|
+
* **Example**
|
|
1684
|
+
*
|
|
1658
1685
|
* ```ts
|
|
1659
1686
|
* import { Array } from "effect"
|
|
1660
1687
|
*
|
|
1661
1688
|
* const array1 = [1, 2, 3]
|
|
1662
1689
|
* const array2 = [2, 3, 4]
|
|
1663
1690
|
* const difference = Array.differenceWith<number>((a, b) => a === b)(array1, array2)
|
|
1664
|
-
*
|
|
1691
|
+
* console.log(difference) // [1]
|
|
1665
1692
|
* ```
|
|
1666
1693
|
*
|
|
1667
1694
|
* @since 2.0.0
|
|
@@ -1674,14 +1701,13 @@ export const differenceWith = isEquivalent => {
|
|
|
1674
1701
|
* Creates a `Array` of values not included in the other given `Iterable`.
|
|
1675
1702
|
* The order and references of result values are determined by the first `Iterable`.
|
|
1676
1703
|
*
|
|
1677
|
-
*
|
|
1704
|
+
* **Example**
|
|
1705
|
+
*
|
|
1678
1706
|
* ```ts
|
|
1679
1707
|
* import { Array } from "effect"
|
|
1680
1708
|
*
|
|
1681
|
-
* const
|
|
1682
|
-
*
|
|
1683
|
-
* const difference = Array.difference(array1, array2)
|
|
1684
|
-
* assert.deepStrictEqual(difference, [1])
|
|
1709
|
+
* const difference = Array.difference([1, 2, 3], [2, 3, 4])
|
|
1710
|
+
* console.log(difference) // [1]
|
|
1685
1711
|
* ```
|
|
1686
1712
|
*
|
|
1687
1713
|
* @since 2.0.0
|
|
@@ -1728,14 +1754,13 @@ export const flatMap = /*#__PURE__*/dual(2, (self, f) => {
|
|
|
1728
1754
|
* from each nested array. This function ensures that the structure of nested
|
|
1729
1755
|
* arrays is collapsed into a single, flat array.
|
|
1730
1756
|
*
|
|
1731
|
-
*
|
|
1732
|
-
* ```ts
|
|
1733
|
-
* import { Array } from "effect";
|
|
1757
|
+
* **Example**
|
|
1734
1758
|
*
|
|
1735
|
-
*
|
|
1736
|
-
*
|
|
1759
|
+
* ```ts
|
|
1760
|
+
* import { Array } from "effect"
|
|
1737
1761
|
*
|
|
1738
|
-
*
|
|
1762
|
+
* const result = Array.flatten([[1, 2], [], [3, 4], [], [5, 6]])
|
|
1763
|
+
* console.log(result) // [1, 2, 3, 4, 5, 6]
|
|
1739
1764
|
* ```
|
|
1740
1765
|
*
|
|
1741
1766
|
* @category sequencing
|
|
@@ -1746,15 +1771,15 @@ export const flatten = /*#__PURE__*/flatMap(identity);
|
|
|
1746
1771
|
* Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.
|
|
1747
1772
|
* This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.
|
|
1748
1773
|
*
|
|
1749
|
-
*
|
|
1774
|
+
* **Example**
|
|
1775
|
+
*
|
|
1750
1776
|
* ```ts
|
|
1751
|
-
* import { Array, Option } from "effect"
|
|
1777
|
+
* import { Array, Option } from "effect"
|
|
1752
1778
|
*
|
|
1753
|
-
* const
|
|
1754
|
-
* const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();
|
|
1755
|
-
* const result = Array.filterMap(data, evenSquares);
|
|
1779
|
+
* const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()
|
|
1756
1780
|
*
|
|
1757
|
-
*
|
|
1781
|
+
* const result = Array.filterMap([1, 2, 3, 4, 5], evenSquares);
|
|
1782
|
+
* console.log(result) // [4, 16]
|
|
1758
1783
|
* ```
|
|
1759
1784
|
*
|
|
1760
1785
|
* @category filtering
|
|
@@ -1776,15 +1801,15 @@ export const filterMap = /*#__PURE__*/dual(2, (self, f) => {
|
|
|
1776
1801
|
* This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.
|
|
1777
1802
|
* This is useful when you need to transform an array but only up to the point where a certain condition holds true.
|
|
1778
1803
|
*
|
|
1779
|
-
*
|
|
1804
|
+
* **Example**
|
|
1805
|
+
*
|
|
1780
1806
|
* ```ts
|
|
1781
|
-
* import { Array, Option } from "effect"
|
|
1807
|
+
* import { Array, Option } from "effect"
|
|
1782
1808
|
*
|
|
1783
|
-
* const
|
|
1784
|
-
* const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();
|
|
1785
|
-
* const result = Array.filterMapWhile(data, toSquareTillOdd);
|
|
1809
|
+
* const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none()
|
|
1786
1810
|
*
|
|
1787
|
-
*
|
|
1811
|
+
* const result = Array.filterMapWhile([2, 4, 5], toSquareTillOdd)
|
|
1812
|
+
* console.log(result) // [4, 16]
|
|
1788
1813
|
* ```
|
|
1789
1814
|
*
|
|
1790
1815
|
* @category filtering
|
|
@@ -1810,20 +1835,21 @@ export const filterMapWhile = /*#__PURE__*/dual(2, (self, f) => {
|
|
|
1810
1835
|
* and you want to separate these types into different collections. For instance, separating validation results
|
|
1811
1836
|
* into successes and failures.
|
|
1812
1837
|
*
|
|
1813
|
-
*
|
|
1838
|
+
* **Example**
|
|
1839
|
+
*
|
|
1814
1840
|
* ```ts
|
|
1815
1841
|
* import { Array, Either } from "effect";
|
|
1816
1842
|
*
|
|
1817
|
-
* const data = [1, 2, 3, 4, 5]
|
|
1818
1843
|
* const isEven = (x: number) => x % 2 === 0
|
|
1819
|
-
*
|
|
1844
|
+
*
|
|
1845
|
+
* const result = Array.partitionMap([1, 2, 3, 4, 5], x =>
|
|
1820
1846
|
* isEven(x) ? Either.right(x) : Either.left(x)
|
|
1821
1847
|
* )
|
|
1822
|
-
*
|
|
1823
|
-
*
|
|
1824
|
-
* [1, 3, 5],
|
|
1825
|
-
* [2, 4]
|
|
1826
|
-
* ]
|
|
1848
|
+
* console.log(result)
|
|
1849
|
+
* // [
|
|
1850
|
+
* // [1, 3, 5],
|
|
1851
|
+
* // [2, 4]
|
|
1852
|
+
* // ]
|
|
1827
1853
|
* ```
|
|
1828
1854
|
*
|
|
1829
1855
|
* @category filtering
|
|
@@ -1846,14 +1872,13 @@ export const partitionMap = /*#__PURE__*/dual(2, (self, f) => {
|
|
|
1846
1872
|
/**
|
|
1847
1873
|
* Retrieves the `Some` values from an `Iterable` of `Option`s, collecting them into an array.
|
|
1848
1874
|
*
|
|
1849
|
-
*
|
|
1875
|
+
* **Example**
|
|
1876
|
+
*
|
|
1850
1877
|
* ```ts
|
|
1851
1878
|
* import { Array, Option } from "effect"
|
|
1852
1879
|
*
|
|
1853
|
-
*
|
|
1854
|
-
*
|
|
1855
|
-
* [1, 2]
|
|
1856
|
-
* )
|
|
1880
|
+
* const result = Array.getSomes([Option.some(1), Option.none(), Option.some(2)])
|
|
1881
|
+
* console.log(result) // [1, 2]
|
|
1857
1882
|
* ```
|
|
1858
1883
|
*
|
|
1859
1884
|
* @category filtering
|
|
@@ -1863,14 +1888,13 @@ export const getSomes = /*#__PURE__*/filterMap(identity);
|
|
|
1863
1888
|
/**
|
|
1864
1889
|
* Retrieves the `Left` values from an `Iterable` of `Either`s, collecting them into an array.
|
|
1865
1890
|
*
|
|
1866
|
-
*
|
|
1891
|
+
* **Example**
|
|
1892
|
+
*
|
|
1867
1893
|
* ```ts
|
|
1868
1894
|
* import { Array, Either } from "effect"
|
|
1869
1895
|
*
|
|
1870
|
-
*
|
|
1871
|
-
*
|
|
1872
|
-
* ["err"]
|
|
1873
|
-
* )
|
|
1896
|
+
* const result = Array.getLefts([Either.right(1), Either.left("err"), Either.right(2)])
|
|
1897
|
+
* console.log(result) // ["err"]
|
|
1874
1898
|
* ```
|
|
1875
1899
|
*
|
|
1876
1900
|
* @category filtering
|
|
@@ -1888,14 +1912,13 @@ export const getLefts = self => {
|
|
|
1888
1912
|
/**
|
|
1889
1913
|
* Retrieves the `Right` values from an `Iterable` of `Either`s, collecting them into an array.
|
|
1890
1914
|
*
|
|
1891
|
-
*
|
|
1915
|
+
* **Example**
|
|
1916
|
+
*
|
|
1892
1917
|
* ```ts
|
|
1893
1918
|
* import { Array, Either } from "effect"
|
|
1894
1919
|
*
|
|
1895
|
-
*
|
|
1896
|
-
*
|
|
1897
|
-
* [1, 2]
|
|
1898
|
-
* )
|
|
1920
|
+
* const result = Array.getRights([Either.right(1), Either.left("err"), Either.right(2)])
|
|
1921
|
+
* console.log(result) // [1, 2]
|
|
1899
1922
|
* ```
|
|
1900
1923
|
*
|
|
1901
1924
|
* @category filtering
|
|
@@ -1927,15 +1950,13 @@ export const filter = /*#__PURE__*/dual(2, (self, predicate) => {
|
|
|
1927
1950
|
/**
|
|
1928
1951
|
* Separate elements based on a predicate that also exposes the index of the element.
|
|
1929
1952
|
*
|
|
1930
|
-
*
|
|
1953
|
+
* **Example**
|
|
1954
|
+
*
|
|
1931
1955
|
* ```ts
|
|
1932
1956
|
* import { Array } from "effect"
|
|
1933
1957
|
*
|
|
1934
|
-
* const
|
|
1935
|
-
*
|
|
1936
|
-
* const result = Array.partition(numbers, n => n % 2 === 0)
|
|
1937
|
-
*
|
|
1938
|
-
* assert.deepStrictEqual(result, [[1, 3], [2, 4]])
|
|
1958
|
+
* const result = Array.partition([1, 2, 3, 4], n => n % 2 === 0)
|
|
1959
|
+
* console.log(result) // [[1, 3], [2, 4]]
|
|
1939
1960
|
* ```
|
|
1940
1961
|
*
|
|
1941
1962
|
* @category filtering
|
|
@@ -1964,13 +1985,13 @@ export const separate = /*#__PURE__*/partitionMap(identity);
|
|
|
1964
1985
|
/**
|
|
1965
1986
|
* Reduces an array from the left.
|
|
1966
1987
|
*
|
|
1967
|
-
*
|
|
1988
|
+
* **Example**
|
|
1989
|
+
*
|
|
1968
1990
|
* ```ts
|
|
1969
1991
|
* import { Array } from "effect"
|
|
1970
1992
|
*
|
|
1971
|
-
* const
|
|
1972
|
-
*
|
|
1973
|
-
* assert.deepStrictEqual(result, 6)
|
|
1993
|
+
* const result = Array.reduce([1, 2, 3], 0, (acc, n) => acc + n)
|
|
1994
|
+
* console.log(result) // 6
|
|
1974
1995
|
* ```
|
|
1975
1996
|
*
|
|
1976
1997
|
* @category folding
|
|
@@ -1980,13 +2001,13 @@ export const reduce = /*#__PURE__*/dual(3, (self, b, f) => fromIterable(self).re
|
|
|
1980
2001
|
/**
|
|
1981
2002
|
* Reduces an array from the right.
|
|
1982
2003
|
*
|
|
1983
|
-
*
|
|
2004
|
+
* **Example**
|
|
2005
|
+
*
|
|
1984
2006
|
* ```ts
|
|
1985
2007
|
* import { Array } from "effect"
|
|
1986
2008
|
*
|
|
1987
|
-
* const
|
|
1988
|
-
*
|
|
1989
|
-
* assert.deepStrictEqual(result, 6)
|
|
2009
|
+
* const result = Array.reduceRight([1, 2, 3], 0, (acc, n) => acc + n)
|
|
2010
|
+
* console.log(result) // 6
|
|
1990
2011
|
* ```
|
|
1991
2012
|
*
|
|
1992
2013
|
* @category folding
|
|
@@ -1996,14 +2017,15 @@ export const reduceRight = /*#__PURE__*/dual(3, (self, b, f) => fromIterable(sel
|
|
|
1996
2017
|
/**
|
|
1997
2018
|
* Lifts a predicate into an array.
|
|
1998
2019
|
*
|
|
1999
|
-
*
|
|
2020
|
+
* **Example**
|
|
2021
|
+
*
|
|
2000
2022
|
* ```ts
|
|
2001
2023
|
* import { Array } from "effect"
|
|
2002
2024
|
*
|
|
2003
2025
|
* const isEven = (n: number) => n % 2 === 0
|
|
2004
2026
|
* const to = Array.liftPredicate(isEven)
|
|
2005
|
-
*
|
|
2006
|
-
*
|
|
2027
|
+
* console.log(to(1)) // []
|
|
2028
|
+
* console.log(to(2)) // [2]
|
|
2007
2029
|
* ```
|
|
2008
2030
|
*
|
|
2009
2031
|
* @category lifting
|
|
@@ -2028,13 +2050,13 @@ export const liftNullable = f => (...a) => fromNullable(f(...a));
|
|
|
2028
2050
|
/**
|
|
2029
2051
|
* Maps over an array and flattens the result, removing null and undefined values.
|
|
2030
2052
|
*
|
|
2031
|
-
*
|
|
2053
|
+
* **Example**
|
|
2054
|
+
*
|
|
2032
2055
|
* ```ts
|
|
2033
2056
|
* import { Array } from "effect"
|
|
2034
2057
|
*
|
|
2035
|
-
* const
|
|
2036
|
-
*
|
|
2037
|
-
* assert.deepStrictEqual(result, [1, 3])
|
|
2058
|
+
* const result = Array.flatMapNullable([1, 2, 3], n => (n % 2 === 0 ? null : n))
|
|
2059
|
+
* console.log(result) // [1, 3]
|
|
2038
2060
|
*
|
|
2039
2061
|
* // Explanation:
|
|
2040
2062
|
* // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers
|
|
@@ -2051,7 +2073,8 @@ export const flatMapNullable = /*#__PURE__*/dual(2, (self, f) => flatMap(self, a
|
|
|
2051
2073
|
* If the `Either` is a left, it returns an empty array.
|
|
2052
2074
|
* If the `Either` is a right, it returns an array with the right value.
|
|
2053
2075
|
*
|
|
2054
|
-
*
|
|
2076
|
+
* **Example**
|
|
2077
|
+
*
|
|
2055
2078
|
* ```ts
|
|
2056
2079
|
* import { Array, Either } from "effect"
|
|
2057
2080
|
*
|
|
@@ -2061,10 +2084,10 @@ export const flatMapNullable = /*#__PURE__*/dual(2, (self, f) => flatMap(self, a
|
|
|
2061
2084
|
* const liftedParseNumber = Array.liftEither(parseNumber)
|
|
2062
2085
|
*
|
|
2063
2086
|
* const result1 = liftedParseNumber("42")
|
|
2064
|
-
*
|
|
2087
|
+
* console.log(result1) // [42]
|
|
2065
2088
|
*
|
|
2066
2089
|
* const result2 = liftedParseNumber("not a number")
|
|
2067
|
-
*
|
|
2090
|
+
* console.log(result2) // []
|
|
2068
2091
|
*
|
|
2069
2092
|
* // Explanation:
|
|
2070
2093
|
* // The function parseNumber is lifted to return an array.
|
|
@@ -2096,13 +2119,13 @@ export const some = /*#__PURE__*/dual(2, (self, predicate) => self.some(predicat
|
|
|
2096
2119
|
/**
|
|
2097
2120
|
* Extends an array with a function that maps each subarray to a value.
|
|
2098
2121
|
*
|
|
2099
|
-
*
|
|
2122
|
+
* **Example**
|
|
2123
|
+
*
|
|
2100
2124
|
* ```ts
|
|
2101
2125
|
* import { Array } from "effect"
|
|
2102
2126
|
*
|
|
2103
|
-
* const
|
|
2104
|
-
*
|
|
2105
|
-
* assert.deepStrictEqual(result, [3, 2, 1])
|
|
2127
|
+
* const result = Array.extend([1, 2, 3], as => as.length)
|
|
2128
|
+
* console.log(result) // [3, 2, 1]
|
|
2106
2129
|
*
|
|
2107
2130
|
* // Explanation:
|
|
2108
2131
|
* // The function maps each subarray starting from each element to its length.
|
|
@@ -2117,12 +2140,13 @@ export const extend = /*#__PURE__*/dual(2, (self, f) => self.map((_, i, as) => f
|
|
|
2117
2140
|
/**
|
|
2118
2141
|
* Finds the minimum element in an array based on a comparator.
|
|
2119
2142
|
*
|
|
2120
|
-
*
|
|
2143
|
+
* **Example**
|
|
2144
|
+
*
|
|
2121
2145
|
* ```ts
|
|
2122
2146
|
* import { Array, Order } from "effect"
|
|
2123
2147
|
*
|
|
2124
|
-
* const
|
|
2125
|
-
*
|
|
2148
|
+
* const result = Array.min([3, 1, 2], Order.number)
|
|
2149
|
+
* console.log(result) // 1
|
|
2126
2150
|
* ```
|
|
2127
2151
|
*
|
|
2128
2152
|
* @since 2.0.0
|
|
@@ -2131,12 +2155,13 @@ export const min = /*#__PURE__*/dual(2, (self, O) => self.reduce(Order.min(O)));
|
|
|
2131
2155
|
/**
|
|
2132
2156
|
* Finds the maximum element in an array based on a comparator.
|
|
2133
2157
|
*
|
|
2134
|
-
*
|
|
2158
|
+
* **Example**
|
|
2159
|
+
*
|
|
2135
2160
|
* ```ts
|
|
2136
2161
|
* import { Array, Order } from "effect"
|
|
2137
2162
|
*
|
|
2138
|
-
* const
|
|
2139
|
-
*
|
|
2163
|
+
* const result = Array.max([3, 1, 2], Order.number)
|
|
2164
|
+
* console.log(result) // 3
|
|
2140
2165
|
* ```
|
|
2141
2166
|
*
|
|
2142
2167
|
* @since 2.0.0
|
|
@@ -2170,14 +2195,13 @@ export const getOrder = Order.array;
|
|
|
2170
2195
|
/**
|
|
2171
2196
|
* Creates an equivalence relation for arrays.
|
|
2172
2197
|
*
|
|
2173
|
-
*
|
|
2198
|
+
* **Example**
|
|
2199
|
+
*
|
|
2174
2200
|
* ```ts
|
|
2175
2201
|
* import { Array } from "effect"
|
|
2176
2202
|
*
|
|
2177
|
-
* const numbers1 = [1, 2, 3]
|
|
2178
|
-
* const numbers2 = [1, 2, 3]
|
|
2179
2203
|
* const eq = Array.getEquivalence<number>((a, b) => a === b)
|
|
2180
|
-
*
|
|
2204
|
+
* console.log(eq([1, 2, 3], [1, 2, 3])) // true
|
|
2181
2205
|
* ```
|
|
2182
2206
|
*
|
|
2183
2207
|
* @category instances
|
|
@@ -2187,12 +2211,12 @@ export const getEquivalence = Equivalence.array;
|
|
|
2187
2211
|
/**
|
|
2188
2212
|
* Performs a side-effect for each element of the `Iterable`.
|
|
2189
2213
|
*
|
|
2190
|
-
*
|
|
2214
|
+
* **Example**
|
|
2215
|
+
*
|
|
2191
2216
|
* ```ts
|
|
2192
2217
|
* import { Array } from "effect"
|
|
2193
2218
|
*
|
|
2194
|
-
*
|
|
2195
|
-
* Array.forEach(numbers, n => console.log(n)) // 1, 2, 3
|
|
2219
|
+
* Array.forEach([1, 2, 3], n => console.log(n)) // 1, 2, 3
|
|
2196
2220
|
* ```
|
|
2197
2221
|
*
|
|
2198
2222
|
* @since 2.0.0
|
|
@@ -2202,13 +2226,13 @@ export const forEach = /*#__PURE__*/dual(2, (self, f) => fromIterable(self).forE
|
|
|
2202
2226
|
* Remove duplicates from an `Iterable` using the provided `isEquivalent` function,
|
|
2203
2227
|
* preserving the order of the first occurrence of each element.
|
|
2204
2228
|
*
|
|
2205
|
-
*
|
|
2229
|
+
* **Example**
|
|
2230
|
+
*
|
|
2206
2231
|
* ```ts
|
|
2207
2232
|
* import { Array } from "effect"
|
|
2208
2233
|
*
|
|
2209
|
-
* const
|
|
2210
|
-
*
|
|
2211
|
-
* assert.deepStrictEqual(unique, [1, 2, 3])
|
|
2234
|
+
* const result = Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b)
|
|
2235
|
+
* console.log(result) // [1, 2, 3]
|
|
2212
2236
|
* ```
|
|
2213
2237
|
*
|
|
2214
2238
|
* @since 2.0.0
|
|
@@ -2237,13 +2261,13 @@ export const dedupe = self => dedupeWith(self, Equal.equivalence());
|
|
|
2237
2261
|
/**
|
|
2238
2262
|
* Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.
|
|
2239
2263
|
*
|
|
2240
|
-
*
|
|
2264
|
+
* **Example**
|
|
2265
|
+
*
|
|
2241
2266
|
* ```ts
|
|
2242
2267
|
* import { Array } from "effect"
|
|
2243
2268
|
*
|
|
2244
|
-
* const
|
|
2245
|
-
*
|
|
2246
|
-
* assert.deepStrictEqual(unique, [1, 2, 3])
|
|
2269
|
+
* const result = Array.dedupeAdjacentWith([1, 1, 2, 2, 3, 3], (a, b) => a === b)
|
|
2270
|
+
* console.log(result) // [1, 2, 3]
|
|
2247
2271
|
* ```
|
|
2248
2272
|
*
|
|
2249
2273
|
* @since 2.0.0
|
|
@@ -2262,13 +2286,13 @@ export const dedupeAdjacentWith = /*#__PURE__*/dual(2, (self, isEquivalent) => {
|
|
|
2262
2286
|
/**
|
|
2263
2287
|
* Deduplicates adjacent elements that are identical.
|
|
2264
2288
|
*
|
|
2265
|
-
*
|
|
2289
|
+
* **Example**
|
|
2290
|
+
*
|
|
2266
2291
|
* ```ts
|
|
2267
2292
|
* import { Array } from "effect"
|
|
2268
2293
|
*
|
|
2269
|
-
* const
|
|
2270
|
-
*
|
|
2271
|
-
* assert.deepStrictEqual(unique, [1, 2, 3])
|
|
2294
|
+
* const result = Array.dedupeAdjacent([1, 1, 2, 2, 3, 3])
|
|
2295
|
+
* console.log(result) // [1, 2, 3]
|
|
2272
2296
|
* ```
|
|
2273
2297
|
*
|
|
2274
2298
|
* @since 2.0.0
|
|
@@ -2277,13 +2301,14 @@ export const dedupeAdjacent = /*#__PURE__*/dedupeAdjacentWith( /*#__PURE__*/Equa
|
|
|
2277
2301
|
/**
|
|
2278
2302
|
* Joins the elements together with "sep" in the middle.
|
|
2279
2303
|
*
|
|
2280
|
-
*
|
|
2304
|
+
* **Example**
|
|
2305
|
+
*
|
|
2281
2306
|
* ```ts
|
|
2282
2307
|
* import { Array } from "effect"
|
|
2283
2308
|
*
|
|
2284
2309
|
* const strings = ["a", "b", "c"]
|
|
2285
2310
|
* const joined = Array.join(strings, "-")
|
|
2286
|
-
*
|
|
2311
|
+
* console.log(joined) // "a-b-c"
|
|
2287
2312
|
* ```
|
|
2288
2313
|
*
|
|
2289
2314
|
* @since 2.0.0
|
|
@@ -2293,13 +2318,13 @@ export const join = /*#__PURE__*/dual(2, (self, sep) => fromIterable(self).join(
|
|
|
2293
2318
|
/**
|
|
2294
2319
|
* Statefully maps over the chunk, producing new elements of type `B`.
|
|
2295
2320
|
*
|
|
2296
|
-
*
|
|
2321
|
+
* **Example**
|
|
2322
|
+
*
|
|
2297
2323
|
* ```ts
|
|
2298
2324
|
* import { Array } from "effect"
|
|
2299
2325
|
*
|
|
2300
|
-
* const
|
|
2301
|
-
*
|
|
2302
|
-
* assert.deepStrictEqual(result, [6, [1, 3, 6]])
|
|
2326
|
+
* const result = Array.mapAccum([1, 2, 3], 0, (acc, n) => [acc + n, acc + n])
|
|
2327
|
+
* console.log(result) // [6, [1, 3, 6]]
|
|
2303
2328
|
* ```
|
|
2304
2329
|
*
|
|
2305
2330
|
* @since 2.0.0
|
|
@@ -2320,14 +2345,13 @@ export const mapAccum = /*#__PURE__*/dual(3, (self, s, f) => {
|
|
|
2320
2345
|
/**
|
|
2321
2346
|
* Zips this chunk crosswise with the specified chunk using the specified combiner.
|
|
2322
2347
|
*
|
|
2323
|
-
*
|
|
2348
|
+
* **Example**
|
|
2349
|
+
*
|
|
2324
2350
|
* ```ts
|
|
2325
2351
|
* import { Array } from "effect"
|
|
2326
2352
|
*
|
|
2327
|
-
* const
|
|
2328
|
-
*
|
|
2329
|
-
* const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)
|
|
2330
|
-
* assert.deepStrictEqual(product, ["1-a", "1-b", "2-a", "2-b"])
|
|
2353
|
+
* const result = Array.cartesianWith([1, 2], ["a", "b"], (a, b) => `${a}-${b}`)
|
|
2354
|
+
* console.log(result) // ["1-a", "1-b", "2-a", "2-b"]
|
|
2331
2355
|
* ```
|
|
2332
2356
|
*
|
|
2333
2357
|
* @since 2.0.0
|
|
@@ -2337,14 +2361,13 @@ export const cartesianWith = /*#__PURE__*/dual(3, (self, that, f) => flatMap(sel
|
|
|
2337
2361
|
/**
|
|
2338
2362
|
* Zips this chunk crosswise with the specified chunk.
|
|
2339
2363
|
*
|
|
2340
|
-
*
|
|
2364
|
+
* **Example**
|
|
2365
|
+
*
|
|
2341
2366
|
* ```ts
|
|
2342
2367
|
* import { Array } from "effect"
|
|
2343
2368
|
*
|
|
2344
|
-
* const
|
|
2345
|
-
*
|
|
2346
|
-
* const product = Array.cartesian(array1, array2)
|
|
2347
|
-
* assert.deepStrictEqual(product, [[1, "a"], [1, "b"], [2, "a"], [2, "b"]])
|
|
2369
|
+
* const result = Array.cartesian([1, 2], ["a", "b"])
|
|
2370
|
+
* console.log(result) // [[1, "a"], [1, "b"], [2, "a"], [2, "b"]]
|
|
2348
2371
|
* ```
|
|
2349
2372
|
*
|
|
2350
2373
|
* @since 2.0.0
|
|
@@ -2368,21 +2391,19 @@ export const cartesian = /*#__PURE__*/dual(2, (self, that) => cartesianWith(self
|
|
|
2368
2391
|
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
2369
2392
|
* 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope
|
|
2370
2393
|
*
|
|
2371
|
-
*
|
|
2372
|
-
* @see {@link bind}
|
|
2373
|
-
* @see {@link let_ let}
|
|
2394
|
+
* **Example**
|
|
2374
2395
|
*
|
|
2375
|
-
* @example
|
|
2376
2396
|
* ```ts
|
|
2377
|
-
* import { Array
|
|
2397
|
+
* import { Array, pipe } from "effect"
|
|
2398
|
+
*
|
|
2378
2399
|
* const doResult = pipe(
|
|
2379
|
-
*
|
|
2380
|
-
*
|
|
2381
|
-
*
|
|
2382
|
-
*
|
|
2383
|
-
*
|
|
2400
|
+
* Array.Do,
|
|
2401
|
+
* Array.bind("x", () => [1, 3, 5]),
|
|
2402
|
+
* Array.bind("y", () => [2, 4, 6]),
|
|
2403
|
+
* Array.filter(({ x, y }) => x < y), // condition
|
|
2404
|
+
* Array.map(({ x, y }) => [x, y] as const) // transformation
|
|
2384
2405
|
* )
|
|
2385
|
-
*
|
|
2406
|
+
* console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]
|
|
2386
2407
|
*
|
|
2387
2408
|
* // equivalent
|
|
2388
2409
|
* const x = [1, 3, 5],
|
|
@@ -2396,6 +2417,10 @@ export const cartesian = /*#__PURE__*/dual(2, (self, that) => cartesianWith(self
|
|
|
2396
2417
|
* }
|
|
2397
2418
|
* ```
|
|
2398
2419
|
*
|
|
2420
|
+
* @see {@link bindTo}
|
|
2421
|
+
* @see {@link bind}
|
|
2422
|
+
* @see {@link let_ let}
|
|
2423
|
+
*
|
|
2399
2424
|
* @category do notation
|
|
2400
2425
|
* @since 3.2.0
|
|
2401
2426
|
*/
|
|
@@ -2414,21 +2439,19 @@ export const Do = /*#__PURE__*/of({});
|
|
|
2414
2439
|
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
2415
2440
|
* 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope
|
|
2416
2441
|
*
|
|
2417
|
-
*
|
|
2418
|
-
* @see {@link Do}
|
|
2419
|
-
* @see {@link let_ let}
|
|
2442
|
+
* **Example**
|
|
2420
2443
|
*
|
|
2421
|
-
* @example
|
|
2422
2444
|
* ```ts
|
|
2423
|
-
* import { Array
|
|
2445
|
+
* import { Array, pipe } from "effect"
|
|
2446
|
+
*
|
|
2424
2447
|
* const doResult = pipe(
|
|
2425
|
-
*
|
|
2426
|
-
*
|
|
2427
|
-
*
|
|
2428
|
-
*
|
|
2429
|
-
*
|
|
2448
|
+
* Array.Do,
|
|
2449
|
+
* Array.bind("x", () => [1, 3, 5]),
|
|
2450
|
+
* Array.bind("y", () => [2, 4, 6]),
|
|
2451
|
+
* Array.filter(({ x, y }) => x < y), // condition
|
|
2452
|
+
* Array.map(({ x, y }) => [x, y] as const) // transformation
|
|
2430
2453
|
* )
|
|
2431
|
-
*
|
|
2454
|
+
* console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]
|
|
2432
2455
|
*
|
|
2433
2456
|
* // equivalent
|
|
2434
2457
|
* const x = [1, 3, 5],
|
|
@@ -2442,6 +2465,10 @@ export const Do = /*#__PURE__*/of({});
|
|
|
2442
2465
|
* }
|
|
2443
2466
|
* ```
|
|
2444
2467
|
*
|
|
2468
|
+
* @see {@link bindTo}
|
|
2469
|
+
* @see {@link Do}
|
|
2470
|
+
* @see {@link let_ let}
|
|
2471
|
+
*
|
|
2445
2472
|
* @category do notation
|
|
2446
2473
|
* @since 3.2.0
|
|
2447
2474
|
*/
|
|
@@ -2460,21 +2487,19 @@ export const bind = /*#__PURE__*/doNotation.bind(map, flatMap);
|
|
|
2460
2487
|
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
2461
2488
|
* 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope
|
|
2462
2489
|
*
|
|
2463
|
-
*
|
|
2464
|
-
* @see {@link Do}
|
|
2465
|
-
* @see {@link let_ let}
|
|
2490
|
+
* **Example**
|
|
2466
2491
|
*
|
|
2467
|
-
* @example
|
|
2468
2492
|
* ```ts
|
|
2469
|
-
* import { Array
|
|
2493
|
+
* import { Array, pipe } from "effect"
|
|
2494
|
+
*
|
|
2470
2495
|
* const doResult = pipe(
|
|
2471
|
-
*
|
|
2472
|
-
*
|
|
2473
|
-
*
|
|
2474
|
-
*
|
|
2475
|
-
*
|
|
2496
|
+
* Array.Do,
|
|
2497
|
+
* Array.bind("x", () => [1, 3, 5]),
|
|
2498
|
+
* Array.bind("y", () => [2, 4, 6]),
|
|
2499
|
+
* Array.filter(({ x, y }) => x < y), // condition
|
|
2500
|
+
* Array.map(({ x, y }) => [x, y] as const) // transformation
|
|
2476
2501
|
* )
|
|
2477
|
-
*
|
|
2502
|
+
* console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]
|
|
2478
2503
|
*
|
|
2479
2504
|
* // equivalent
|
|
2480
2505
|
* const x = [1, 3, 5],
|
|
@@ -2488,6 +2513,10 @@ export const bind = /*#__PURE__*/doNotation.bind(map, flatMap);
|
|
|
2488
2513
|
* }
|
|
2489
2514
|
* ```
|
|
2490
2515
|
*
|
|
2516
|
+
* @see {@link bindTo}
|
|
2517
|
+
* @see {@link Do}
|
|
2518
|
+
* @see {@link let_ let}
|
|
2519
|
+
*
|
|
2491
2520
|
* @category do notation
|
|
2492
2521
|
* @since 3.2.0
|
|
2493
2522
|
*/
|
|
@@ -2508,21 +2537,19 @@ export {
|
|
|
2508
2537
|
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
2509
2538
|
* 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope
|
|
2510
2539
|
*
|
|
2511
|
-
*
|
|
2512
|
-
* @see {@link bind}
|
|
2513
|
-
* @see {@link Do}
|
|
2540
|
+
* **Example**
|
|
2514
2541
|
*
|
|
2515
|
-
* @example
|
|
2516
2542
|
* ```ts
|
|
2517
|
-
* import { Array
|
|
2543
|
+
* import { Array, pipe } from "effect"
|
|
2544
|
+
*
|
|
2518
2545
|
* const doResult = pipe(
|
|
2519
|
-
*
|
|
2520
|
-
*
|
|
2521
|
-
*
|
|
2522
|
-
*
|
|
2523
|
-
*
|
|
2546
|
+
* Array.Do,
|
|
2547
|
+
* Array.bind("x", () => [1, 3, 5]),
|
|
2548
|
+
* Array.bind("y", () => [2, 4, 6]),
|
|
2549
|
+
* Array.filter(({ x, y }) => x < y), // condition
|
|
2550
|
+
* Array.map(({ x, y }) => [x, y] as const) // transformation
|
|
2524
2551
|
* )
|
|
2525
|
-
*
|
|
2552
|
+
* console.log(doResult) // [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]]
|
|
2526
2553
|
*
|
|
2527
2554
|
* // equivalent
|
|
2528
2555
|
* const x = [1, 3, 5],
|
|
@@ -2536,6 +2563,11 @@ export {
|
|
|
2536
2563
|
* }
|
|
2537
2564
|
*
|
|
2538
2565
|
* ```
|
|
2566
|
+
*
|
|
2567
|
+
* @see {@link bindTo}
|
|
2568
|
+
* @see {@link bind}
|
|
2569
|
+
* @see {@link Do}
|
|
2570
|
+
*
|
|
2539
2571
|
* @category do notation
|
|
2540
2572
|
* @since 3.2.0
|
|
2541
2573
|
*/
|