@@ -6,6 +6,23 @@ import type { AsyncOptional, ConcurOptional, Optional } from './optionals.js'
6
6
* A reducer that reduces by combining pairs of values using function
7
7
* application.
8
8
*
9
+ * @example
10
+ * ```js playground
11
+ * import { or, pipe, reduce } from 'lfi'
12
+ *
13
+ * console.log(
14
+ * pipe(
15
+ * [1, 2, 3, 4],
16
+ * reduce(
17
+ * // This is a `FunctionReducer`
18
+ * (number1, number2) => number1 + number2,
19
+ * ),
20
+ * or(() => 0),
21
+ * ),
22
+ * )
23
+ * //=> 10
24
+ * ```
25
+ *
9
26
* @category Reducers
10
27
* @since v2.0.0
11
28
*/
@@ -18,6 +35,25 @@ export type FunctionReducer<Value = unknown> = (
18
35
* A reducer that reduces by combining pairs of values using
19
36
* {@link RawOptionalReducerWithoutFinish.add}.
20
37
*
38
+ * @example
39
+ * ```js playground
40
+ * import { or, pipe, reduce } from 'lfi'
41
+ *
42
+ * console.log(
43
+ * pipe(
44
+ * [1, 2, 3, 4],
45
+ * reduce(
46
+ * // This is a `RawOptionalReducerWithoutFinish`
47
+ * {
48
+ * add: (number1, number2) => number1 + number2,
49
+ * },
50
+ * ),
51
+ * or(() => 0),
52
+ * ),
53
+ * )
54
+ * //=> 10
55
+ * ```
56
+ *
21
57
* @category Reducers
22
58
* @since v2.0.0
23
59
*/
@@ -30,6 +66,26 @@ export type RawOptionalReducerWithoutFinish<Value = unknown, This = unknown> = {
30
66
* {@link RawOptionalReducerWithoutFinish.add} and then transforming the final
31
67
* value using {@link RawOptionalReducerWithFinish.finish}.
32
68
*
69
+ * @example
70
+ * ```js playground
71
+ * import { or, pipe, reduce } from 'lfi'
72
+ *
73
+ * console.log(
74
+ * pipe(
75
+ * [1, 2, 3, 4],
76
+ * reduce(
77
+ * // This is a `RawOptionalReducerWithFinish`
78
+ * {
79
+ * add: (number1, number2) => number1 + number2,
80
+ * finish: sum => `The sum is ${sum}`,
81
+ * },
82
+ * ),
83
+ * or(() => `There are no numbers`),
84
+ * ),
85
+ * )
86
+ * //=> The sum is 10
87
+ * ```
88
+ *
33
89
* @category Reducers
34
90
* @since v2.0.0
35
91
*/
@@ -46,6 +102,29 @@ export type RawOptionalReducerWithFinish<
46
102
* {@link RawOptionalReducerWithoutFinish.add} and then transforming the final
47
103
* value using {@link RawOptionalReducerWithFinish.finish}.
48
104
*
105
+ * It's identical to {@link RawOptionalReducerWithFinish} except its `this` is
106
+ * bound by {@link normalizeReducer}.
107
+ *
108
+ * @example
109
+ * ```js playground
110
+ * import { or, pipe, reduce } from 'lfi'
111
+ *
112
+ * console.log(
113
+ * pipe(
114
+ * [1, 2, 3, 4],
115
+ * reduce(
116
+ * // This will be an `OptionalReducer` once it's normalized by `reduce`
117
+ * {
118
+ * add: (number1, number2) => number1 + number2,
119
+ * finish: sum => `The sum is ${sum}`,
120
+ * },
121
+ * ),
122
+ * or(() => `There are no numbers`),
123
+ * ),
124
+ * )
125
+ * //=> The sum is 10
126
+ * ```
127
+ *
49
128
* @category Reducers
50
129
* @since v2.0.0
51
130
*/
@@ -59,6 +138,25 @@ export type OptionalReducer<
59
138
* {@link RawReducerWithoutFinish.create} and then adding values to the
60
139
* accumulator values using {@link RawReducerWithoutFinish.add}.
61
140
*
141
+ * @example
142
+ * ```js playground
143
+ * import { pipe, reduce } from 'lfi'
144
+ *
145
+ * console.log(
146
+ * pipe(
147
+ * [1, 2, 3, 4],
148
+ * reduce(
149
+ * // This is a `RawReducerWithoutFinish`
150
+ * {
151
+ * create: () => 0,
152
+ * add: (number1, number2) => number1 + number2,
153
+ * },
154
+ * ),
155
+ * ),
156
+ * )
157
+ * //=> 10
158
+ * ```
159
+ *
62
160
* @category Reducers
63
161
* @since v2.0.0
64
162
*/
@@ -77,6 +175,26 @@ export type RawReducerWithoutFinish<
77
175
* values using {@link RawReducerWithoutFinish.add}, and then transforming the
78
176
* final accumulator using {@link RawReducerWithFinish.finish}.
79
177
*
178
+ * @example
179
+ * ```js playground
180
+ * import { pipe, reduce } from 'lfi'
181
+ *
182
+ * console.log(
183
+ * pipe(
184
+ * [1, 2, 3, 4],
185
+ * reduce(
186
+ * // This is a `RawReducerWithFinish`
187
+ * {
188
+ * create: () => 0,
189
+ * add: (number1, number2) => number1 + number2,
190
+ * finish: sum => `The sum is ${sum}`,
191
+ * },
192
+ * ),
193
+ * ),
194
+ * )
195
+ * //=> The sum is 10
196
+ * ```
197
+ *
80
198
* @category Reducers
81
199
* @since v2.0.0
82
200
*/
@@ -95,6 +213,29 @@ export type RawReducerWithFinish<
95
213
* values using {@link RawReducerWithoutFinish.add}, and then transforming the
96
214
* final accumulator using {@link RawReducerWithFinish.finish}.
97
215
*
216
+ * It's identical to {@link RawReducerWithFinish} except its `this` is bound by
217
+ * {@link normalizeReducer}.
218
+ *
219
+ * @example
220
+ * ```js playground
221
+ * import { pipe, reduce } from 'lfi'
222
+ *
223
+ * console.log(
224
+ * pipe(
225
+ * [1, 2, 3, 4],
226
+ * reduce(
227
+ * // This will be a `Reducer` once it's normalized by `reduce`
228
+ * {
229
+ * create: () => 0,
230
+ * add: (number1, number2) => number1 + number2,
231
+ * finish: sum => `The sum is ${sum}`,
232
+ * },
233
+ * ),
234
+ * ),
235
+ * )
236
+ * //=> The sum is 10
237
+ * ```
238
+ *
98
239
* @category Reducers
99
240
* @since v2.0.0
100
241
*/
0 commit comments