@@ -14,7 +14,9 @@ import type {
14
14
* Returns a {@link Reducer} that collects values to an `Array`.
15
15
*
16
16
* @example
17
- * ```js
17
+ * ```js playground
18
+ * import { cycle, pipe, reduce, take, toArray } from 'lfi'
19
+ *
18
20
* console.log(
19
21
* pipe(
20
22
* cycle([`sloth`, `more sloth`]),
@@ -34,12 +36,14 @@ export const toArray: <Value>() => Reducer<Value, Value[]>
34
36
* Returns a {@link Reducer} that collects values to a `Set`.
35
37
*
36
38
* @example
37
- * ```js
39
+ * ```js playground
40
+ * import { cycle, pipe, reduce, take, toSet } from 'lfi'
41
+ *
38
42
* console.log(
39
43
* pipe(
40
44
* cycle([`sloth`, `more sloth`]),
41
45
* take(4),
42
- * reduce(toArray ()),
46
+ * reduce(toSet ()),
43
47
* ),
44
48
* )
45
49
* //=> Set(2) { 'sloth', 'more sloth' }
@@ -54,7 +58,9 @@ export const toSet: <Value>() => Reducer<Value, Set<Value>>
54
58
* Returns a {@link Reducer} that collects objects to a `WeakSet`.
55
59
*
56
60
* @example
57
- * ```js
61
+ * ```js playground
62
+ * import { cycle, map, pipe, reduce, take, toWeakSet } from 'lfi'
63
+ *
58
64
* console.log(
59
65
* pipe(
60
66
* cycle([`sloth`, `more sloth`]),
@@ -80,15 +86,21 @@ export const toWeakSet: <Value extends object>() => Reducer<
80
86
* In the case of pairs with duplicate keys, the value of the last one wins.
81
87
*
82
88
* @example
83
- * ```js
89
+ * ```js playground
90
+ * import { map, pipe, reduce, toObject } from 'lfi'
91
+ *
84
92
* console.log(
85
93
* pipe(
86
94
* [`sloth`, `more sloth`, `even more sloth`],
87
95
* map(string => [string, string.length]),
88
96
* reduce(toObject()),
89
97
* ),
90
98
* )
91
- * //=> { sloth: 5, 'more sloth': 10, 'even more sloth': 15 }
99
+ * //=> {
100
+ * //=> sloth: 5,
101
+ * //=> 'more sloth': 10,
102
+ * //=> 'even more sloth': 15
103
+ * //=> }
92
104
* ```
93
105
*
94
106
* @category Collections
@@ -106,15 +118,21 @@ export const toObject: <Key extends keyof never, Value>() => RawKeyedReducer<
106
118
* In the case of pairs with duplicate keys, the value of the last one wins.
107
119
*
108
120
* @example
109
- * ```js
121
+ * ```js playground
122
+ * import { map, pipe, reduce, toMap } from 'lfi'
123
+ *
110
124
* console.log(
111
125
* pipe(
112
126
* [`sloth`, `more sloth`, `even more sloth`],
113
127
* map(string => [string, string.length]),
114
128
* reduce(toMap()),
115
129
* ),
116
130
* )
117
- * //=> Map(3) { 'sloth' => 5, 'more sloth' => 10, 'even more sloth' => 15 }
131
+ * //=> Map(3) {
132
+ * //=> 'sloth' => 5,
133
+ * //=> 'more sloth' => 10,
134
+ * //=> 'even more sloth' => 15
135
+ * //=> }
118
136
* ```
119
137
*
120
138
* @category Collections
@@ -132,7 +150,9 @@ export const toMap: <Key, Value>() => RawKeyedReducer<
132
150
* In the case of pairs with duplicate keys, the value of the last one wins.
133
151
*
134
152
* @example
135
- * ```js
153
+ * ```js playground
154
+ * import { map, pipe, reduce, toWeakMap } from 'lfi'
155
+ *
136
156
* console.log(
137
157
* pipe(
138
158
* [`sloth`, `more sloth`, `even more sloth`],
@@ -157,7 +177,9 @@ export const toWeakMap: <Key extends object, Value>() => RawKeyedReducer<
157
177
* and reduces values with the same key using `innerReducer`.
158
178
*
159
179
* @example
160
- * ```js
180
+ * ```js playground
181
+ * import { map, pipe, reduce, toArray, toGrouped, toMap } from 'lfi'
182
+ *
161
183
* console.log(
162
184
* pipe(
163
185
* [`sloth`, `some sloth`, `sleep`, `more sloth`, `even more sloth`],
@@ -252,15 +274,21 @@ export const toGrouped: {
252
274
* an {@link OptionalReducer}. Otherwise, returns a {@link Reducer}.
253
275
*
254
276
* @example
255
- * ```js
277
+ * ```js playground
278
+ * import { map, pipe, reduce, toCount, toJoin, toMultiple, toSet } from 'lfi'
279
+ *
256
280
* console.log(
257
281
* pipe(
258
282
* [`sloth`, `some sloth`, `sleep`, `more sloth`, `even more sloth`],
259
283
* map(string => string.length),
260
284
* reduce(toMultiple([toSet(), toCount(), toJoin(`,`)])),
261
285
* ),
262
286
* )
263
- * //=> [ Set(3) { 5, 10, 15 }, 5, '5,10,5,10,15' ]
287
+ * //=> [
288
+ * //=> Set(3) { 5, 10, 15 },
289
+ * //=> 5,
290
+ * //=> '5,10,5,10,15'
291
+ * //=> ]
264
292
*
265
293
* console.log(
266
294
* pipe(
@@ -275,7 +303,11 @@ export const toGrouped: {
275
303
* ),
276
304
* ),
277
305
* )
278
- * //=> { set: Set(3) { 5, 10, 15 }, count: 5, string: '5,10,5,10,15' }
306
+ * //=> {
307
+ * //=> set: Set(3) { 5, 10, 15 },
308
+ * //=> count: 5,
309
+ * //=> string: '5,10,5,10,15'
310
+ * //=> }
279
311
* ```
280
312
*
281
313
* @category Collections
@@ -366,15 +398,20 @@ export const toMultiple: {
366
398
* {@link joinConcur} for direct use on iterables.
367
399
*
368
400
* @example
369
- * ```js
401
+ * ```js playground
402
+ * import { map, pipe, reduce, toGrouped, toJoin, toMap } from 'lfi'
403
+ *
370
404
* console.log(
371
405
* pipe(
372
406
* [`sloth`, `more sloth`, `sleep`, `some sloth`],
373
407
* map(string => [string.length, string]),
374
408
* reduce(toGrouped(toJoin(`,`), toMap())),
375
409
* ),
376
410
* )
377
- * //=> Map(2) { 5 => 'sloth,sleep', 10 => 'more sloth,some sloth' }
411
+ * //=> Map(2) {
412
+ * //=> 5 => 'sloth,sleep',
413
+ * //=> 10 => 'more sloth,some sloth'
414
+ * //=> }
378
415
* ```
379
416
*
380
417
* @category Collections
@@ -383,21 +420,24 @@ export const toMultiple: {
383
420
export const toJoin : ( separator : string ) => Reducer < unknown , unknown , string >
384
421
385
422
/**
386
- * Returns the result of concatenating the values of `iterable` to a string
387
- * where values are separated by `separator`.
423
+ * Returns the string concatenation of the values of `iterable`, separated by
424
+ * `separator`.
388
425
*
389
- * Like `Array.prototype.join`, but for iterables, but does not treat `null`,
390
- * `undefined`, or `[]` specially.
426
+ * Like `Array.prototype.join`, but for iterables, except it does not treat
427
+ * `null`, ` undefined`, or `[]` specially.
391
428
*
392
429
* @example
393
- * ```js
430
+ * ```js playground
431
+ * import { join, map, pipe } from 'lfi'
432
+ *
394
433
* console.log(
395
434
* pipe(
396
435
* [`sloth`, `more sloth`, `even more sloth`],
436
+ * map(string => string.toUpperCase()),
397
437
* join(`, `),
398
438
* ),
399
439
* )
400
- * //=> sloth, more sloth, even more sloth
440
+ * //=> SLOTH, MORE SLOTH, EVEN MORE SLOTH
401
441
* ```
402
442
*
403
443
* @category Collections
@@ -409,21 +449,24 @@ export const join: {
409
449
}
410
450
411
451
/**
412
- * Returns a promise that resolves to the result of concatenating the values of
413
- * `asyncIterable` to a string where values are separated by `separator`.
452
+ * Returns a promise that resolves to the string concatenation of the values of
453
+ * `asyncIterable`, separated by `separator`.
414
454
*
415
- * Like `Array.prototype.join`, but for async iterables, but does not treat
416
- * `null`, `undefined`, or `[]` specially.
455
+ * Like `Array.prototype.join`, but for async iterables, except it does not
456
+ * treat `null`, `undefined`, or `[]` specially.
417
457
*
418
458
* @example
419
- * ```js
459
+ * ```js playground
460
+ * import { asAsync, joinAsync, mapAsync, pipe } from 'lfi'
461
+ *
420
462
* console.log(
421
463
* await pipe(
422
464
* asAsync([`sloth`, `more sloth`, `even more sloth`]),
465
+ * mapAsync(string => string.toUpperCase()),
423
466
* joinAsync(`, `),
424
467
* ),
425
468
* )
426
- * //=> sloth, more sloth, even more sloth
469
+ * //=> SLOTH, MORE SLOTH, EVEN MORE SLOTH
427
470
* ```
428
471
*
429
472
* @category Collections
@@ -437,21 +480,27 @@ export const joinAsync: {
437
480
}
438
481
439
482
/**
440
- * Returns a promise that resolves to the result of concatenating the values of
441
- * `concurIterable` to a string where values are separated by `separator`.
483
+ * Returns a promise that resolves to the string concatenation of the values of
484
+ * `concurIterable`, separated by `separator`.
442
485
*
443
- * Like `Array.prototype.join`, but for concur iterables, but does not treat
444
- * `null`, `undefined`, or `[]` specially.
486
+ * Like `Array.prototype.join`, but for concur iterables, except it does not
487
+ * treat `null`, `undefined`, or `[]` specially.
488
+ *
489
+ * WARNING: The iteration order of concur iterables is not deterministic, so the
490
+ * values will be concatenated in an arbitrary order.
445
491
*
446
492
* @example
447
- * ```js
493
+ * ```js playground
494
+ * import { asConcur, joinConcur, mapConcur, pipe } from 'lfi'
495
+ *
448
496
* console.log(
449
497
* await pipe(
450
498
* asConcur([`sloth`, `more sloth`, `even more sloth`]),
499
+ * mapConcur(string => string.toUpperCase()),
451
500
* joinConcur(`, `),
452
501
* ),
453
502
* )
454
- * //=> sloth, more sloth, even more sloth
503
+ * //=> SLOTH, MORE SLOTH, EVEN MORE SLOTH
455
504
* ```
456
505
*
457
506
* @category Collections
0 commit comments