Skip to content

Commit 3c69268

Browse files
feat(website): add a bunch of reducer tsdoc playground examples (#63)
1 parent 708271f commit 3c69268

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed

src/operations/reducers.d.ts

+141
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ import type { AsyncOptional, ConcurOptional, Optional } from './optionals.js'
66
* A reducer that reduces by combining pairs of values using function
77
* application.
88
*
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+
*
926
* @category Reducers
1027
* @since v2.0.0
1128
*/
@@ -18,6 +35,25 @@ export type FunctionReducer<Value = unknown> = (
1835
* A reducer that reduces by combining pairs of values using
1936
* {@link RawOptionalReducerWithoutFinish.add}.
2037
*
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+
*
2157
* @category Reducers
2258
* @since v2.0.0
2359
*/
@@ -30,6 +66,26 @@ export type RawOptionalReducerWithoutFinish<Value = unknown, This = unknown> = {
3066
* {@link RawOptionalReducerWithoutFinish.add} and then transforming the final
3167
* value using {@link RawOptionalReducerWithFinish.finish}.
3268
*
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+
*
3389
* @category Reducers
3490
* @since v2.0.0
3591
*/
@@ -46,6 +102,29 @@ export type RawOptionalReducerWithFinish<
46102
* {@link RawOptionalReducerWithoutFinish.add} and then transforming the final
47103
* value using {@link RawOptionalReducerWithFinish.finish}.
48104
*
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+
*
49128
* @category Reducers
50129
* @since v2.0.0
51130
*/
@@ -59,6 +138,25 @@ export type OptionalReducer<
59138
* {@link RawReducerWithoutFinish.create} and then adding values to the
60139
* accumulator values using {@link RawReducerWithoutFinish.add}.
61140
*
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+
*
62160
* @category Reducers
63161
* @since v2.0.0
64162
*/
@@ -77,6 +175,26 @@ export type RawReducerWithoutFinish<
77175
* values using {@link RawReducerWithoutFinish.add}, and then transforming the
78176
* final accumulator using {@link RawReducerWithFinish.finish}.
79177
*
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+
*
80198
* @category Reducers
81199
* @since v2.0.0
82200
*/
@@ -95,6 +213,29 @@ export type RawReducerWithFinish<
95213
* values using {@link RawReducerWithoutFinish.add}, and then transforming the
96214
* final accumulator using {@link RawReducerWithFinish.finish}.
97215
*
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+
*
98239
* @category Reducers
99240
* @since v2.0.0
100241
*/

0 commit comments

Comments
 (0)