effect 4.0.0-beta.7 → 4.0.0-beta.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/Combiner.d.ts +280 -13
- package/dist/Combiner.d.ts.map +1 -1
- package/dist/Combiner.js +198 -7
- package/dist/Combiner.js.map +1 -1
- package/dist/Reducer.d.ts +166 -7
- package/dist/Reducer.d.ts.map +1 -1
- package/dist/Reducer.js +135 -1
- package/dist/Reducer.js.map +1 -1
- package/dist/index.d.ts +124 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +124 -0
- package/dist/index.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +3 -3
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +3 -3
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +21 -39
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js +15 -24
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +18 -16
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/process/ChildProcess.d.ts +1 -1
- package/dist/unstable/process/ChildProcess.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +5 -5
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js +2 -2
- package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/unstable/sql/SqlSchema.d.ts +1 -1
- package/dist/unstable/sql/SqlSchema.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Combiner.ts +280 -13
- package/src/Reducer.ts +166 -7
- package/src/index.ts +124 -0
- package/src/unstable/httpapi/HttpApiBuilder.ts +3 -3
- package/src/unstable/httpapi/HttpApiClient.ts +3 -3
- package/src/unstable/httpapi/HttpApiEndpoint.ts +47 -72
- package/src/unstable/httpapi/OpenApi.ts +18 -16
- package/src/unstable/process/ChildProcess.ts +1 -1
- package/src/unstable/reactivity/AtomHttpApi.ts +16 -15
- package/src/unstable/sql/SqlSchema.ts +1 -1
package/dist/Reducer.d.ts
CHANGED
|
@@ -1,15 +1,105 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* A module for reducing collections of values into a single result.
|
|
3
|
+
*
|
|
4
|
+
* A `Reducer<A>` extends {@link Combiner.Combiner} by adding an
|
|
5
|
+
* `initialValue` (identity element) and a `combineAll` method that folds an
|
|
6
|
+
* entire collection. Think `Array.prototype.reduce`, but packaged as a
|
|
7
|
+
* reusable, composable value.
|
|
8
|
+
*
|
|
9
|
+
* ## Mental model
|
|
10
|
+
*
|
|
11
|
+
* - **Reducer** – a {@link Combiner.Combiner} plus an `initialValue` and a
|
|
12
|
+
* `combineAll` method.
|
|
13
|
+
* - **initialValue** – the neutral/identity element. Combining any value with
|
|
14
|
+
* `initialValue` should return the original value unchanged (e.g. `0` for
|
|
15
|
+
* addition, `""` for string concatenation).
|
|
16
|
+
* - **combineAll** – folds an `Iterable<A>` starting from `initialValue`.
|
|
17
|
+
* When omitted from {@link make}, a default left-to-right fold is used.
|
|
18
|
+
* - **Purity** – all reducers produced by this module are pure; they never
|
|
19
|
+
* mutate their arguments.
|
|
20
|
+
* - **Composability** – reducers can be lifted into `Option`, `Struct`,
|
|
21
|
+
* `Tuple`, `Record`, and other container types via helpers in those modules.
|
|
22
|
+
* - **Subtype of Combiner** – every `Reducer` is also a valid
|
|
23
|
+
* `Combiner`, so you can pass a `Reducer` anywhere a `Combiner` is
|
|
24
|
+
* expected.
|
|
25
|
+
*
|
|
26
|
+
* ## Common tasks
|
|
27
|
+
*
|
|
28
|
+
* - Create a reducer from a combine function and initial value → {@link make}
|
|
29
|
+
* - Swap argument order → {@link flip}
|
|
30
|
+
* - Combine two values without an initial value → use {@link Combiner.Combiner}
|
|
31
|
+
* instead
|
|
32
|
+
*
|
|
33
|
+
* ## Gotchas
|
|
34
|
+
*
|
|
35
|
+
* - `combineAll` on an empty iterable returns `initialValue`, not an error.
|
|
36
|
+
* - The default `combineAll` folds left-to-right. If your `combine` is not
|
|
37
|
+
* associative, order matters. Pass a custom `combineAll` to {@link make} if
|
|
38
|
+
* you need different traversal or short-circuiting.
|
|
39
|
+
* - A `Reducer` is also a valid `Combiner` — but a `Combiner` is *not* a
|
|
40
|
+
* `Reducer` (it lacks `initialValue`).
|
|
41
|
+
*
|
|
42
|
+
* ## Quickstart
|
|
43
|
+
*
|
|
44
|
+
* **Example** (summing a list of numbers)
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { Reducer } from "effect"
|
|
48
|
+
*
|
|
49
|
+
* const Sum = Reducer.make<number>((a, b) => a + b, 0)
|
|
50
|
+
*
|
|
51
|
+
* console.log(Sum.combine(3, 4))
|
|
52
|
+
* // Output: 7
|
|
53
|
+
*
|
|
54
|
+
* console.log(Sum.combineAll([1, 2, 3, 4]))
|
|
55
|
+
* // Output: 10
|
|
56
|
+
*
|
|
57
|
+
* console.log(Sum.combineAll([]))
|
|
58
|
+
* // Output: 0
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* ## See also
|
|
62
|
+
*
|
|
63
|
+
* - {@link make} – the primary constructor
|
|
64
|
+
* - {@link Reducer} – the core interface
|
|
65
|
+
* - {@link Combiner.Combiner} – the parent interface (no `initialValue`)
|
|
66
|
+
*
|
|
2
67
|
* @since 4.0.0
|
|
3
68
|
*/
|
|
4
69
|
import type * as Combiner from "./Combiner.ts";
|
|
5
70
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
71
|
+
* Represents a strategy for reducing a collection of values of type `A` into
|
|
72
|
+
* a single result.
|
|
73
|
+
*
|
|
74
|
+
* Extends {@link Combiner.Combiner} with:
|
|
75
|
+
* - `initialValue` – the identity/neutral element for `combine`.
|
|
76
|
+
* - `combineAll` – folds an entire `Iterable<A>` from `initialValue`.
|
|
77
|
+
*
|
|
78
|
+
* When to use:
|
|
79
|
+
* - You need to fold/reduce a collection into a single value.
|
|
80
|
+
* - You want a reusable reducing strategy that can be passed to library
|
|
81
|
+
* functions like `Struct.makeReducer`, `Option.makeReducer`, or
|
|
82
|
+
* `Record.makeReducerUnion`.
|
|
83
|
+
* - You need both the combining logic *and* a known starting value.
|
|
84
|
+
*
|
|
85
|
+
* Many modules ship pre-built reducers:
|
|
86
|
+
* - `Number.ReducerSum`, `Number.ReducerMultiply`
|
|
87
|
+
* - `String.ReducerConcat`
|
|
88
|
+
* - `Boolean.ReducerAnd`, `Boolean.ReducerOr`
|
|
8
89
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
90
|
+
* **Example** (string concatenation reducer)
|
|
91
|
+
*
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { Reducer } from "effect"
|
|
94
|
+
*
|
|
95
|
+
* const Concat = Reducer.make<string>((a, b) => a + b, "")
|
|
96
|
+
*
|
|
97
|
+
* console.log(Concat.combineAll(["hello", " ", "world"]))
|
|
98
|
+
* // Output: "hello world"
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @see {@link make} – create a `Reducer` from a function and initial value
|
|
102
|
+
* @see {@link Combiner.Combiner} – parent interface without `initialValue`
|
|
13
103
|
*
|
|
14
104
|
* @category model
|
|
15
105
|
* @since 4.0.0
|
|
@@ -23,12 +113,81 @@ export interface Reducer<A> extends Combiner.Combiner<A> {
|
|
|
23
113
|
/**
|
|
24
114
|
* Creates a `Reducer` from a `combine` function and an `initialValue`.
|
|
25
115
|
*
|
|
26
|
-
*
|
|
116
|
+
* When to use:
|
|
117
|
+
* - You have a custom reducing operation not covered by a pre-built reducer.
|
|
118
|
+
* - You want to provide an optimized `combineAll` (e.g. short-circuiting on
|
|
119
|
+
* a known absorbing element like `0` for multiplication).
|
|
120
|
+
*
|
|
121
|
+
* Behavior:
|
|
122
|
+
* - If `combineAll` is omitted, a default left-to-right fold starting from
|
|
123
|
+
* `initialValue` is used.
|
|
124
|
+
* - If `combineAll` is provided, it completely replaces the default fold.
|
|
125
|
+
* - Pure – the returned reducer does not mutate its arguments.
|
|
126
|
+
*
|
|
127
|
+
* **Example** (multiplication with short-circuit)
|
|
128
|
+
*
|
|
129
|
+
* ```ts
|
|
130
|
+
* import { Reducer } from "effect"
|
|
131
|
+
*
|
|
132
|
+
* const Product = Reducer.make<number>(
|
|
133
|
+
* (a, b) => a * b,
|
|
134
|
+
* 1,
|
|
135
|
+
* (collection) => {
|
|
136
|
+
* let acc = 1
|
|
137
|
+
* for (const n of collection) {
|
|
138
|
+
* if (n === 0) return 0
|
|
139
|
+
* acc *= n
|
|
140
|
+
* }
|
|
141
|
+
* return acc
|
|
142
|
+
* }
|
|
143
|
+
* )
|
|
144
|
+
*
|
|
145
|
+
* console.log(Product.combineAll([2, 3, 4]))
|
|
146
|
+
* // Output: 24
|
|
147
|
+
*
|
|
148
|
+
* console.log(Product.combineAll([2, 0, 4]))
|
|
149
|
+
* // Output: 0
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* @see {@link Reducer} – the interface this creates
|
|
153
|
+
* @see {@link flip} – reverse the argument order
|
|
27
154
|
*
|
|
28
155
|
* @since 4.0.0
|
|
29
156
|
*/
|
|
30
157
|
export declare function make<A>(combine: (self: A, that: A) => A, initialValue: A, combineAll?: (collection: Iterable<A>) => A): Reducer<A>;
|
|
31
158
|
/**
|
|
159
|
+
* Reverses the argument order of a reducer's `combine` method.
|
|
160
|
+
*
|
|
161
|
+
* When to use:
|
|
162
|
+
* - You need the "right" value to act as the accumulator side.
|
|
163
|
+
* - You want to reverse the natural direction of a non-commutative reducer
|
|
164
|
+
* (e.g. string concatenation becomes prepend).
|
|
165
|
+
*
|
|
166
|
+
* Behavior:
|
|
167
|
+
* - Returns a new `Reducer` where `combine(self, that)` calls the original
|
|
168
|
+
* reducer as `combine(that, self)`.
|
|
169
|
+
* - The `initialValue` is preserved from the original reducer.
|
|
170
|
+
* - The `combineAll` is re-derived from the flipped `combine` (using the
|
|
171
|
+
* default left-to-right fold), not carried over from the original.
|
|
172
|
+
* - Does not mutate the input reducer.
|
|
173
|
+
*
|
|
174
|
+
* **Example** (reversing string concatenation)
|
|
175
|
+
*
|
|
176
|
+
* ```ts
|
|
177
|
+
* import { Reducer, String } from "effect"
|
|
178
|
+
*
|
|
179
|
+
* const Prepend = Reducer.flip(String.ReducerConcat)
|
|
180
|
+
*
|
|
181
|
+
* console.log(Prepend.combine("a", "b"))
|
|
182
|
+
* // Output: "ba"
|
|
183
|
+
*
|
|
184
|
+
* console.log(Prepend.combineAll(["a", "b", "c"]))
|
|
185
|
+
* // Output: "cba"
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* @see {@link make}
|
|
189
|
+
* @see {@link Combiner.flip} – the same operation on a plain `Combiner`
|
|
190
|
+
*
|
|
32
191
|
* @since 4.0.0
|
|
33
192
|
*/
|
|
34
193
|
export declare function flip<A>(reducer: Reducer<A>): Reducer<A>;
|
package/dist/Reducer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Reducer.d.ts","sourceRoot":"","sources":["../src/Reducer.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Reducer.d.ts","sourceRoot":"","sources":["../src/Reducer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AAEH,OAAO,KAAK,KAAK,QAAQ,MAAM,eAAe,CAAA;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,WAAW,OAAO,CAAC,CAAC,CAAE,SAAQ,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;IACtD,oEAAoE;IACpE,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAA;IAExB,2EAA2E;IAC3E,QAAQ,CAAC,UAAU,EAAE,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;CACpD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,IAAI,CAAC,CAAC,EACpB,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAChC,YAAY,EAAE,CAAC,EACf,UAAU,CAAC,EAAE,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,GAC1C,OAAO,CAAC,CAAC,CAAC,CAaZ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAEvD"}
|
package/dist/Reducer.js
CHANGED
|
@@ -1,10 +1,112 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* A module for reducing collections of values into a single result.
|
|
3
|
+
*
|
|
4
|
+
* A `Reducer<A>` extends {@link Combiner.Combiner} by adding an
|
|
5
|
+
* `initialValue` (identity element) and a `combineAll` method that folds an
|
|
6
|
+
* entire collection. Think `Array.prototype.reduce`, but packaged as a
|
|
7
|
+
* reusable, composable value.
|
|
8
|
+
*
|
|
9
|
+
* ## Mental model
|
|
10
|
+
*
|
|
11
|
+
* - **Reducer** – a {@link Combiner.Combiner} plus an `initialValue` and a
|
|
12
|
+
* `combineAll` method.
|
|
13
|
+
* - **initialValue** – the neutral/identity element. Combining any value with
|
|
14
|
+
* `initialValue` should return the original value unchanged (e.g. `0` for
|
|
15
|
+
* addition, `""` for string concatenation).
|
|
16
|
+
* - **combineAll** – folds an `Iterable<A>` starting from `initialValue`.
|
|
17
|
+
* When omitted from {@link make}, a default left-to-right fold is used.
|
|
18
|
+
* - **Purity** – all reducers produced by this module are pure; they never
|
|
19
|
+
* mutate their arguments.
|
|
20
|
+
* - **Composability** – reducers can be lifted into `Option`, `Struct`,
|
|
21
|
+
* `Tuple`, `Record`, and other container types via helpers in those modules.
|
|
22
|
+
* - **Subtype of Combiner** – every `Reducer` is also a valid
|
|
23
|
+
* `Combiner`, so you can pass a `Reducer` anywhere a `Combiner` is
|
|
24
|
+
* expected.
|
|
25
|
+
*
|
|
26
|
+
* ## Common tasks
|
|
27
|
+
*
|
|
28
|
+
* - Create a reducer from a combine function and initial value → {@link make}
|
|
29
|
+
* - Swap argument order → {@link flip}
|
|
30
|
+
* - Combine two values without an initial value → use {@link Combiner.Combiner}
|
|
31
|
+
* instead
|
|
32
|
+
*
|
|
33
|
+
* ## Gotchas
|
|
34
|
+
*
|
|
35
|
+
* - `combineAll` on an empty iterable returns `initialValue`, not an error.
|
|
36
|
+
* - The default `combineAll` folds left-to-right. If your `combine` is not
|
|
37
|
+
* associative, order matters. Pass a custom `combineAll` to {@link make} if
|
|
38
|
+
* you need different traversal or short-circuiting.
|
|
39
|
+
* - A `Reducer` is also a valid `Combiner` — but a `Combiner` is *not* a
|
|
40
|
+
* `Reducer` (it lacks `initialValue`).
|
|
41
|
+
*
|
|
42
|
+
* ## Quickstart
|
|
43
|
+
*
|
|
44
|
+
* **Example** (summing a list of numbers)
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { Reducer } from "effect"
|
|
48
|
+
*
|
|
49
|
+
* const Sum = Reducer.make<number>((a, b) => a + b, 0)
|
|
50
|
+
*
|
|
51
|
+
* console.log(Sum.combine(3, 4))
|
|
52
|
+
* // Output: 7
|
|
53
|
+
*
|
|
54
|
+
* console.log(Sum.combineAll([1, 2, 3, 4]))
|
|
55
|
+
* // Output: 10
|
|
56
|
+
*
|
|
57
|
+
* console.log(Sum.combineAll([]))
|
|
58
|
+
* // Output: 0
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* ## See also
|
|
62
|
+
*
|
|
63
|
+
* - {@link make} – the primary constructor
|
|
64
|
+
* - {@link Reducer} – the core interface
|
|
65
|
+
* - {@link Combiner.Combiner} – the parent interface (no `initialValue`)
|
|
66
|
+
*
|
|
2
67
|
* @since 4.0.0
|
|
3
68
|
*/
|
|
4
69
|
/**
|
|
5
70
|
* Creates a `Reducer` from a `combine` function and an `initialValue`.
|
|
6
71
|
*
|
|
7
|
-
*
|
|
72
|
+
* When to use:
|
|
73
|
+
* - You have a custom reducing operation not covered by a pre-built reducer.
|
|
74
|
+
* - You want to provide an optimized `combineAll` (e.g. short-circuiting on
|
|
75
|
+
* a known absorbing element like `0` for multiplication).
|
|
76
|
+
*
|
|
77
|
+
* Behavior:
|
|
78
|
+
* - If `combineAll` is omitted, a default left-to-right fold starting from
|
|
79
|
+
* `initialValue` is used.
|
|
80
|
+
* - If `combineAll` is provided, it completely replaces the default fold.
|
|
81
|
+
* - Pure – the returned reducer does not mutate its arguments.
|
|
82
|
+
*
|
|
83
|
+
* **Example** (multiplication with short-circuit)
|
|
84
|
+
*
|
|
85
|
+
* ```ts
|
|
86
|
+
* import { Reducer } from "effect"
|
|
87
|
+
*
|
|
88
|
+
* const Product = Reducer.make<number>(
|
|
89
|
+
* (a, b) => a * b,
|
|
90
|
+
* 1,
|
|
91
|
+
* (collection) => {
|
|
92
|
+
* let acc = 1
|
|
93
|
+
* for (const n of collection) {
|
|
94
|
+
* if (n === 0) return 0
|
|
95
|
+
* acc *= n
|
|
96
|
+
* }
|
|
97
|
+
* return acc
|
|
98
|
+
* }
|
|
99
|
+
* )
|
|
100
|
+
*
|
|
101
|
+
* console.log(Product.combineAll([2, 3, 4]))
|
|
102
|
+
* // Output: 24
|
|
103
|
+
*
|
|
104
|
+
* console.log(Product.combineAll([2, 0, 4]))
|
|
105
|
+
* // Output: 0
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @see {@link Reducer} – the interface this creates
|
|
109
|
+
* @see {@link flip} – reverse the argument order
|
|
8
110
|
*
|
|
9
111
|
* @since 4.0.0
|
|
10
112
|
*/
|
|
@@ -22,6 +124,38 @@ export function make(combine, initialValue, combineAll) {
|
|
|
22
124
|
};
|
|
23
125
|
}
|
|
24
126
|
/**
|
|
127
|
+
* Reverses the argument order of a reducer's `combine` method.
|
|
128
|
+
*
|
|
129
|
+
* When to use:
|
|
130
|
+
* - You need the "right" value to act as the accumulator side.
|
|
131
|
+
* - You want to reverse the natural direction of a non-commutative reducer
|
|
132
|
+
* (e.g. string concatenation becomes prepend).
|
|
133
|
+
*
|
|
134
|
+
* Behavior:
|
|
135
|
+
* - Returns a new `Reducer` where `combine(self, that)` calls the original
|
|
136
|
+
* reducer as `combine(that, self)`.
|
|
137
|
+
* - The `initialValue` is preserved from the original reducer.
|
|
138
|
+
* - The `combineAll` is re-derived from the flipped `combine` (using the
|
|
139
|
+
* default left-to-right fold), not carried over from the original.
|
|
140
|
+
* - Does not mutate the input reducer.
|
|
141
|
+
*
|
|
142
|
+
* **Example** (reversing string concatenation)
|
|
143
|
+
*
|
|
144
|
+
* ```ts
|
|
145
|
+
* import { Reducer, String } from "effect"
|
|
146
|
+
*
|
|
147
|
+
* const Prepend = Reducer.flip(String.ReducerConcat)
|
|
148
|
+
*
|
|
149
|
+
* console.log(Prepend.combine("a", "b"))
|
|
150
|
+
* // Output: "ba"
|
|
151
|
+
*
|
|
152
|
+
* console.log(Prepend.combineAll(["a", "b", "c"]))
|
|
153
|
+
* // Output: "cba"
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* @see {@link make}
|
|
157
|
+
* @see {@link Combiner.flip} – the same operation on a plain `Combiner`
|
|
158
|
+
*
|
|
25
159
|
* @since 4.0.0
|
|
26
160
|
*/
|
|
27
161
|
export function flip(reducer) {
|
package/dist/Reducer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Reducer.js","names":["make","combine","initialValue","combineAll","collection","out","value","flip","reducer","self","that"],"sources":["../src/Reducer.ts"],"sourcesContent":[null],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Reducer.js","names":["make","combine","initialValue","combineAll","collection","out","value","flip","reducer","self","that"],"sources":["../src/Reducer.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,OAAM,SAAUA,IAAIA,CAClBC,OAAgC,EAChCC,YAAe,EACfC,UAA2C;EAE3C,OAAO;IACLF,OAAO;IACPC,YAAY;IACZC,UAAU,EAAEA,UAAU,KAClBC,UAAU,IAAI;MACd,IAAIC,GAAG,GAAGH,YAAY;MACtB,KAAK,MAAMI,KAAK,IAAIF,UAAU,EAAE;QAC9BC,GAAG,GAAGJ,OAAO,CAACI,GAAG,EAAEC,KAAK,CAAC;MAC3B;MACA,OAAOD,GAAG;IACZ,CAAC;GACJ;AACH;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,OAAM,SAAUE,IAAIA,CAAIC,OAAmB;EACzC,OAAOR,IAAI,CAAC,CAACS,IAAI,EAAEC,IAAI,KAAKF,OAAO,CAACP,OAAO,CAACS,IAAI,EAAED,IAAI,CAAC,EAAED,OAAO,CAACN,YAAY,CAAC;AAChF","ignoreList":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -428,6 +428,65 @@ export * as Chunk from "./Chunk.ts";
|
|
|
428
428
|
*/
|
|
429
429
|
export * as Clock from "./Clock.ts";
|
|
430
430
|
/**
|
|
431
|
+
* A module for combining two values of the same type into one.
|
|
432
|
+
*
|
|
433
|
+
* A `Combiner<A>` wraps a single binary function `(self: A, that: A) => A`.
|
|
434
|
+
* It describes *how* two values merge but carries no initial/empty value
|
|
435
|
+
* (for that, see {@link Reducer} which extends `Combiner` with an
|
|
436
|
+
* `initialValue`).
|
|
437
|
+
*
|
|
438
|
+
* ## Mental model
|
|
439
|
+
*
|
|
440
|
+
* - **Combiner** – an object with a `combine(self, that)` method that returns
|
|
441
|
+
* a value of the same type.
|
|
442
|
+
* - **Argument order** – `self` is the "left" / accumulator side, `that` is
|
|
443
|
+
* the "right" / incoming side.
|
|
444
|
+
* - **No identity element** – unlike a monoid, a `Combiner` does not require
|
|
445
|
+
* a neutral element. Use {@link Reducer} when you need one.
|
|
446
|
+
* - **Purity** – all combiners produced by this module are pure; they never
|
|
447
|
+
* mutate their arguments.
|
|
448
|
+
* - **Composability** – combiners can be lifted into `Option`, `Struct`,
|
|
449
|
+
* `Tuple`, and other container types via helpers in those modules.
|
|
450
|
+
*
|
|
451
|
+
* ## Common tasks
|
|
452
|
+
*
|
|
453
|
+
* - Create a combiner from any binary function → {@link make}
|
|
454
|
+
* - Swap argument order → {@link flip}
|
|
455
|
+
* - Pick the smaller / larger of two values → {@link min} / {@link max}
|
|
456
|
+
* - Always keep the first or last value → {@link first} / {@link last}
|
|
457
|
+
* - Ignore both values and return a fixed result → {@link constant}
|
|
458
|
+
* - Insert a separator between combined values → {@link intercalate}
|
|
459
|
+
*
|
|
460
|
+
* ## Gotchas
|
|
461
|
+
*
|
|
462
|
+
* - `min` and `max` require an `Order<A>`, not a raw comparator. Import from
|
|
463
|
+
* e.g. `Number.Order` or `String.Order`.
|
|
464
|
+
* - `intercalate` is curried: call it with the separator first, then pass the
|
|
465
|
+
* base combiner.
|
|
466
|
+
* - A `Reducer` (which adds `initialValue`) is also a valid `Combiner` — you
|
|
467
|
+
* can pass a `Reducer` anywhere a `Combiner` is expected.
|
|
468
|
+
*
|
|
469
|
+
* ## Quickstart
|
|
470
|
+
*
|
|
471
|
+
* **Example** (combining strings with a separator)
|
|
472
|
+
*
|
|
473
|
+
* ```ts
|
|
474
|
+
* import { Combiner, String } from "effect"
|
|
475
|
+
*
|
|
476
|
+
* const csv = Combiner.intercalate(",")(String.ReducerConcat)
|
|
477
|
+
*
|
|
478
|
+
* console.log(csv.combine("a", "b"))
|
|
479
|
+
* // Output: "a,b"
|
|
480
|
+
*
|
|
481
|
+
* console.log(csv.combine(csv.combine("a", "b"), "c"))
|
|
482
|
+
* // Output: "a,b,c"
|
|
483
|
+
* ```
|
|
484
|
+
*
|
|
485
|
+
* ## See also
|
|
486
|
+
*
|
|
487
|
+
* - {@link make} – the primary constructor
|
|
488
|
+
* - {@link Combiner} – the core interface
|
|
489
|
+
*
|
|
431
490
|
* @since 4.0.0
|
|
432
491
|
*/
|
|
433
492
|
export * as Combiner from "./Combiner.ts";
|
|
@@ -2506,6 +2565,71 @@ export * as Redactable from "./Redactable.ts";
|
|
|
2506
2565
|
*/
|
|
2507
2566
|
export * as Redacted from "./Redacted.ts";
|
|
2508
2567
|
/**
|
|
2568
|
+
* A module for reducing collections of values into a single result.
|
|
2569
|
+
*
|
|
2570
|
+
* A `Reducer<A>` extends {@link Combiner.Combiner} by adding an
|
|
2571
|
+
* `initialValue` (identity element) and a `combineAll` method that folds an
|
|
2572
|
+
* entire collection. Think `Array.prototype.reduce`, but packaged as a
|
|
2573
|
+
* reusable, composable value.
|
|
2574
|
+
*
|
|
2575
|
+
* ## Mental model
|
|
2576
|
+
*
|
|
2577
|
+
* - **Reducer** – a {@link Combiner.Combiner} plus an `initialValue` and a
|
|
2578
|
+
* `combineAll` method.
|
|
2579
|
+
* - **initialValue** – the neutral/identity element. Combining any value with
|
|
2580
|
+
* `initialValue` should return the original value unchanged (e.g. `0` for
|
|
2581
|
+
* addition, `""` for string concatenation).
|
|
2582
|
+
* - **combineAll** – folds an `Iterable<A>` starting from `initialValue`.
|
|
2583
|
+
* When omitted from {@link make}, a default left-to-right fold is used.
|
|
2584
|
+
* - **Purity** – all reducers produced by this module are pure; they never
|
|
2585
|
+
* mutate their arguments.
|
|
2586
|
+
* - **Composability** – reducers can be lifted into `Option`, `Struct`,
|
|
2587
|
+
* `Tuple`, `Record`, and other container types via helpers in those modules.
|
|
2588
|
+
* - **Subtype of Combiner** – every `Reducer` is also a valid
|
|
2589
|
+
* `Combiner`, so you can pass a `Reducer` anywhere a `Combiner` is
|
|
2590
|
+
* expected.
|
|
2591
|
+
*
|
|
2592
|
+
* ## Common tasks
|
|
2593
|
+
*
|
|
2594
|
+
* - Create a reducer from a combine function and initial value → {@link make}
|
|
2595
|
+
* - Swap argument order → {@link flip}
|
|
2596
|
+
* - Combine two values without an initial value → use {@link Combiner.Combiner}
|
|
2597
|
+
* instead
|
|
2598
|
+
*
|
|
2599
|
+
* ## Gotchas
|
|
2600
|
+
*
|
|
2601
|
+
* - `combineAll` on an empty iterable returns `initialValue`, not an error.
|
|
2602
|
+
* - The default `combineAll` folds left-to-right. If your `combine` is not
|
|
2603
|
+
* associative, order matters. Pass a custom `combineAll` to {@link make} if
|
|
2604
|
+
* you need different traversal or short-circuiting.
|
|
2605
|
+
* - A `Reducer` is also a valid `Combiner` — but a `Combiner` is *not* a
|
|
2606
|
+
* `Reducer` (it lacks `initialValue`).
|
|
2607
|
+
*
|
|
2608
|
+
* ## Quickstart
|
|
2609
|
+
*
|
|
2610
|
+
* **Example** (summing a list of numbers)
|
|
2611
|
+
*
|
|
2612
|
+
* ```ts
|
|
2613
|
+
* import { Reducer } from "effect"
|
|
2614
|
+
*
|
|
2615
|
+
* const Sum = Reducer.make<number>((a, b) => a + b, 0)
|
|
2616
|
+
*
|
|
2617
|
+
* console.log(Sum.combine(3, 4))
|
|
2618
|
+
* // Output: 7
|
|
2619
|
+
*
|
|
2620
|
+
* console.log(Sum.combineAll([1, 2, 3, 4]))
|
|
2621
|
+
* // Output: 10
|
|
2622
|
+
*
|
|
2623
|
+
* console.log(Sum.combineAll([]))
|
|
2624
|
+
* // Output: 0
|
|
2625
|
+
* ```
|
|
2626
|
+
*
|
|
2627
|
+
* ## See also
|
|
2628
|
+
*
|
|
2629
|
+
* - {@link make} – the primary constructor
|
|
2630
|
+
* - {@link Reducer} – the core interface
|
|
2631
|
+
* - {@link Combiner.Combiner} – the parent interface (no `initialValue`)
|
|
2632
|
+
*
|
|
2509
2633
|
* @since 4.0.0
|
|
2510
2634
|
*/
|
|
2511
2635
|
export * as Reducer from "./Reducer.ts";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO;AACL;;GAEG;AACH,MAAM;AACN;;GAEG;AACH,YAAY;AACZ;;GAEG;AACH,IAAI;AACJ;;GAEG;AACH,IAAI;AACJ;;GAEG;AACH,QAAQ;AACR;;GAEG;AACH,IAAI,EACL,MAAM,eAAe,CAAA;AAItB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoFG;AACH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAE7C;;;;;GAKG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;;;GAKG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC;;;;;;GAMG;AACH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC;;GAEG;AACH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;AACH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC;;GAEG;AACH,OAAO,KAAK,aAAa,MAAM,o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KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC;;GAEG;AACH,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAE/C;;GAEG;AACH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC;;GAEG;AACH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -429,6 +429,65 @@ export * as Chunk from "./Chunk.js";
|
|
|
429
429
|
*/
|
|
430
430
|
export * as Clock from "./Clock.js";
|
|
431
431
|
/**
|
|
432
|
+
* A module for combining two values of the same type into one.
|
|
433
|
+
*
|
|
434
|
+
* A `Combiner<A>` wraps a single binary function `(self: A, that: A) => A`.
|
|
435
|
+
* It describes *how* two values merge but carries no initial/empty value
|
|
436
|
+
* (for that, see {@link Reducer} which extends `Combiner` with an
|
|
437
|
+
* `initialValue`).
|
|
438
|
+
*
|
|
439
|
+
* ## Mental model
|
|
440
|
+
*
|
|
441
|
+
* - **Combiner** – an object with a `combine(self, that)` method that returns
|
|
442
|
+
* a value of the same type.
|
|
443
|
+
* - **Argument order** – `self` is the "left" / accumulator side, `that` is
|
|
444
|
+
* the "right" / incoming side.
|
|
445
|
+
* - **No identity element** – unlike a monoid, a `Combiner` does not require
|
|
446
|
+
* a neutral element. Use {@link Reducer} when you need one.
|
|
447
|
+
* - **Purity** – all combiners produced by this module are pure; they never
|
|
448
|
+
* mutate their arguments.
|
|
449
|
+
* - **Composability** – combiners can be lifted into `Option`, `Struct`,
|
|
450
|
+
* `Tuple`, and other container types via helpers in those modules.
|
|
451
|
+
*
|
|
452
|
+
* ## Common tasks
|
|
453
|
+
*
|
|
454
|
+
* - Create a combiner from any binary function → {@link make}
|
|
455
|
+
* - Swap argument order → {@link flip}
|
|
456
|
+
* - Pick the smaller / larger of two values → {@link min} / {@link max}
|
|
457
|
+
* - Always keep the first or last value → {@link first} / {@link last}
|
|
458
|
+
* - Ignore both values and return a fixed result → {@link constant}
|
|
459
|
+
* - Insert a separator between combined values → {@link intercalate}
|
|
460
|
+
*
|
|
461
|
+
* ## Gotchas
|
|
462
|
+
*
|
|
463
|
+
* - `min` and `max` require an `Order<A>`, not a raw comparator. Import from
|
|
464
|
+
* e.g. `Number.Order` or `String.Order`.
|
|
465
|
+
* - `intercalate` is curried: call it with the separator first, then pass the
|
|
466
|
+
* base combiner.
|
|
467
|
+
* - A `Reducer` (which adds `initialValue`) is also a valid `Combiner` — you
|
|
468
|
+
* can pass a `Reducer` anywhere a `Combiner` is expected.
|
|
469
|
+
*
|
|
470
|
+
* ## Quickstart
|
|
471
|
+
*
|
|
472
|
+
* **Example** (combining strings with a separator)
|
|
473
|
+
*
|
|
474
|
+
* ```ts
|
|
475
|
+
* import { Combiner, String } from "effect"
|
|
476
|
+
*
|
|
477
|
+
* const csv = Combiner.intercalate(",")(String.ReducerConcat)
|
|
478
|
+
*
|
|
479
|
+
* console.log(csv.combine("a", "b"))
|
|
480
|
+
* // Output: "a,b"
|
|
481
|
+
*
|
|
482
|
+
* console.log(csv.combine(csv.combine("a", "b"), "c"))
|
|
483
|
+
* // Output: "a,b,c"
|
|
484
|
+
* ```
|
|
485
|
+
*
|
|
486
|
+
* ## See also
|
|
487
|
+
*
|
|
488
|
+
* - {@link make} – the primary constructor
|
|
489
|
+
* - {@link Combiner} – the core interface
|
|
490
|
+
*
|
|
432
491
|
* @since 4.0.0
|
|
433
492
|
*/
|
|
434
493
|
export * as Combiner from "./Combiner.js";
|
|
@@ -2507,6 +2566,71 @@ export * as Redactable from "./Redactable.js";
|
|
|
2507
2566
|
*/
|
|
2508
2567
|
export * as Redacted from "./Redacted.js";
|
|
2509
2568
|
/**
|
|
2569
|
+
* A module for reducing collections of values into a single result.
|
|
2570
|
+
*
|
|
2571
|
+
* A `Reducer<A>` extends {@link Combiner.Combiner} by adding an
|
|
2572
|
+
* `initialValue` (identity element) and a `combineAll` method that folds an
|
|
2573
|
+
* entire collection. Think `Array.prototype.reduce`, but packaged as a
|
|
2574
|
+
* reusable, composable value.
|
|
2575
|
+
*
|
|
2576
|
+
* ## Mental model
|
|
2577
|
+
*
|
|
2578
|
+
* - **Reducer** – a {@link Combiner.Combiner} plus an `initialValue` and a
|
|
2579
|
+
* `combineAll` method.
|
|
2580
|
+
* - **initialValue** – the neutral/identity element. Combining any value with
|
|
2581
|
+
* `initialValue` should return the original value unchanged (e.g. `0` for
|
|
2582
|
+
* addition, `""` for string concatenation).
|
|
2583
|
+
* - **combineAll** – folds an `Iterable<A>` starting from `initialValue`.
|
|
2584
|
+
* When omitted from {@link make}, a default left-to-right fold is used.
|
|
2585
|
+
* - **Purity** – all reducers produced by this module are pure; they never
|
|
2586
|
+
* mutate their arguments.
|
|
2587
|
+
* - **Composability** – reducers can be lifted into `Option`, `Struct`,
|
|
2588
|
+
* `Tuple`, `Record`, and other container types via helpers in those modules.
|
|
2589
|
+
* - **Subtype of Combiner** – every `Reducer` is also a valid
|
|
2590
|
+
* `Combiner`, so you can pass a `Reducer` anywhere a `Combiner` is
|
|
2591
|
+
* expected.
|
|
2592
|
+
*
|
|
2593
|
+
* ## Common tasks
|
|
2594
|
+
*
|
|
2595
|
+
* - Create a reducer from a combine function and initial value → {@link make}
|
|
2596
|
+
* - Swap argument order → {@link flip}
|
|
2597
|
+
* - Combine two values without an initial value → use {@link Combiner.Combiner}
|
|
2598
|
+
* instead
|
|
2599
|
+
*
|
|
2600
|
+
* ## Gotchas
|
|
2601
|
+
*
|
|
2602
|
+
* - `combineAll` on an empty iterable returns `initialValue`, not an error.
|
|
2603
|
+
* - The default `combineAll` folds left-to-right. If your `combine` is not
|
|
2604
|
+
* associative, order matters. Pass a custom `combineAll` to {@link make} if
|
|
2605
|
+
* you need different traversal or short-circuiting.
|
|
2606
|
+
* - A `Reducer` is also a valid `Combiner` — but a `Combiner` is *not* a
|
|
2607
|
+
* `Reducer` (it lacks `initialValue`).
|
|
2608
|
+
*
|
|
2609
|
+
* ## Quickstart
|
|
2610
|
+
*
|
|
2611
|
+
* **Example** (summing a list of numbers)
|
|
2612
|
+
*
|
|
2613
|
+
* ```ts
|
|
2614
|
+
* import { Reducer } from "effect"
|
|
2615
|
+
*
|
|
2616
|
+
* const Sum = Reducer.make<number>((a, b) => a + b, 0)
|
|
2617
|
+
*
|
|
2618
|
+
* console.log(Sum.combine(3, 4))
|
|
2619
|
+
* // Output: 7
|
|
2620
|
+
*
|
|
2621
|
+
* console.log(Sum.combineAll([1, 2, 3, 4]))
|
|
2622
|
+
* // Output: 10
|
|
2623
|
+
*
|
|
2624
|
+
* console.log(Sum.combineAll([]))
|
|
2625
|
+
* // Output: 0
|
|
2626
|
+
* ```
|
|
2627
|
+
*
|
|
2628
|
+
* ## See also
|
|
2629
|
+
*
|
|
2630
|
+
* - {@link make} – the primary constructor
|
|
2631
|
+
* - {@link Reducer} – the core interface
|
|
2632
|
+
* - {@link Combiner.Combiner} – the parent interface (no `initialValue`)
|
|
2633
|
+
*
|
|
2510
2634
|
* @since 4.0.0
|
|
2511
2635
|
*/
|
|
2512
2636
|
export * as Reducer from "./Reducer.js";
|