Skip to content

Commit ec7c95e

Browse files
committed
feat(website): revisions and playground for all tsdoc examples
1 parent d603675 commit ec7c95e

File tree

6 files changed

+233
-83
lines changed

6 files changed

+233
-83
lines changed

pnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/operations/collections.d.ts

+82-33
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import type {
1414
* Returns a {@link Reducer} that collects values to an `Array`.
1515
*
1616
* @example
17-
* ```js
17+
* ```js playground
18+
* import { cycle, pipe, reduce, take, toArray } from 'lfi'
19+
*
1820
* console.log(
1921
* pipe(
2022
* cycle([`sloth`, `more sloth`]),
@@ -34,12 +36,14 @@ export const toArray: <Value>() => Reducer<Value, Value[]>
3436
* Returns a {@link Reducer} that collects values to a `Set`.
3537
*
3638
* @example
37-
* ```js
39+
* ```js playground
40+
* import { cycle, pipe, reduce, take, toSet } from 'lfi'
41+
*
3842
* console.log(
3943
* pipe(
4044
* cycle([`sloth`, `more sloth`]),
4145
* take(4),
42-
* reduce(toArray()),
46+
* reduce(toSet()),
4347
* ),
4448
* )
4549
* //=> Set(2) { 'sloth', 'more sloth' }
@@ -54,7 +58,9 @@ export const toSet: <Value>() => Reducer<Value, Set<Value>>
5458
* Returns a {@link Reducer} that collects objects to a `WeakSet`.
5559
*
5660
* @example
57-
* ```js
61+
* ```js playground
62+
* import { cycle, map, pipe, reduce, take, toWeakSet } from 'lfi'
63+
*
5864
* console.log(
5965
* pipe(
6066
* cycle([`sloth`, `more sloth`]),
@@ -80,15 +86,21 @@ export const toWeakSet: <Value extends object>() => Reducer<
8086
* In the case of pairs with duplicate keys, the value of the last one wins.
8187
*
8288
* @example
83-
* ```js
89+
* ```js playground
90+
* import { map, pipe, reduce, toObject } from 'lfi'
91+
*
8492
* console.log(
8593
* pipe(
8694
* [`sloth`, `more sloth`, `even more sloth`],
8795
* map(string => [string, string.length]),
8896
* reduce(toObject()),
8997
* ),
9098
* )
91-
* //=> { sloth: 5, 'more sloth': 10, 'even more sloth': 15 }
99+
* //=> {
100+
* //=> sloth: 5,
101+
* //=> 'more sloth': 10,
102+
* //=> 'even more sloth': 15
103+
* //=> }
92104
* ```
93105
*
94106
* @category Collections
@@ -106,15 +118,21 @@ export const toObject: <Key extends keyof never, Value>() => RawKeyedReducer<
106118
* In the case of pairs with duplicate keys, the value of the last one wins.
107119
*
108120
* @example
109-
* ```js
121+
* ```js playground
122+
* import { map, pipe, reduce, toMap } from 'lfi'
123+
*
110124
* console.log(
111125
* pipe(
112126
* [`sloth`, `more sloth`, `even more sloth`],
113127
* map(string => [string, string.length]),
114128
* reduce(toMap()),
115129
* ),
116130
* )
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+
* //=> }
118136
* ```
119137
*
120138
* @category Collections
@@ -132,7 +150,9 @@ export const toMap: <Key, Value>() => RawKeyedReducer<
132150
* In the case of pairs with duplicate keys, the value of the last one wins.
133151
*
134152
* @example
135-
* ```js
153+
* ```js playground
154+
* import { map, pipe, reduce, toWeakMap } from 'lfi'
155+
*
136156
* console.log(
137157
* pipe(
138158
* [`sloth`, `more sloth`, `even more sloth`],
@@ -157,7 +177,9 @@ export const toWeakMap: <Key extends object, Value>() => RawKeyedReducer<
157177
* and reduces values with the same key using `innerReducer`.
158178
*
159179
* @example
160-
* ```js
180+
* ```js playground
181+
* import { map, pipe, reduce, toArray, toGrouped, toMap } from 'lfi'
182+
*
161183
* console.log(
162184
* pipe(
163185
* [`sloth`, `some sloth`, `sleep`, `more sloth`, `even more sloth`],
@@ -252,15 +274,21 @@ export const toGrouped: {
252274
* an {@link OptionalReducer}. Otherwise, returns a {@link Reducer}.
253275
*
254276
* @example
255-
* ```js
277+
* ```js playground
278+
* import { map, pipe, reduce, toCount, toJoin, toMultiple, toSet } from 'lfi'
279+
*
256280
* console.log(
257281
* pipe(
258282
* [`sloth`, `some sloth`, `sleep`, `more sloth`, `even more sloth`],
259283
* map(string => string.length),
260284
* reduce(toMultiple([toSet(), toCount(), toJoin(`,`)])),
261285
* ),
262286
* )
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+
* //=> ]
264292
*
265293
* console.log(
266294
* pipe(
@@ -275,7 +303,11 @@ export const toGrouped: {
275303
* ),
276304
* ),
277305
* )
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+
* //=> }
279311
* ```
280312
*
281313
* @category Collections
@@ -366,15 +398,20 @@ export const toMultiple: {
366398
* {@link joinConcur} for direct use on iterables.
367399
*
368400
* @example
369-
* ```js
401+
* ```js playground
402+
* import { map, pipe, reduce, toGrouped, toJoin, toMap } from 'lfi'
403+
*
370404
* console.log(
371405
* pipe(
372406
* [`sloth`, `more sloth`, `sleep`, `some sloth`],
373407
* map(string => [string.length, string]),
374408
* reduce(toGrouped(toJoin(`,`), toMap())),
375409
* ),
376410
* )
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+
* //=> }
378415
* ```
379416
*
380417
* @category Collections
@@ -383,21 +420,24 @@ export const toMultiple: {
383420
export const toJoin: (separator: string) => Reducer<unknown, unknown, string>
384421

385422
/**
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`.
388425
*
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.
391428
*
392429
* @example
393-
* ```js
430+
* ```js playground
431+
* import { join, map, pipe } from 'lfi'
432+
*
394433
* console.log(
395434
* pipe(
396435
* [`sloth`, `more sloth`, `even more sloth`],
436+
* map(string => string.toUpperCase()),
397437
* join(`, `),
398438
* ),
399439
* )
400-
* //=> sloth, more sloth, even more sloth
440+
* //=> SLOTH, MORE SLOTH, EVEN MORE SLOTH
401441
* ```
402442
*
403443
* @category Collections
@@ -409,21 +449,24 @@ export const join: {
409449
}
410450

411451
/**
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`.
414454
*
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.
417457
*
418458
* @example
419-
* ```js
459+
* ```js playground
460+
* import { asAsync, joinAsync, mapAsync, pipe } from 'lfi'
461+
*
420462
* console.log(
421463
* await pipe(
422464
* asAsync([`sloth`, `more sloth`, `even more sloth`]),
465+
* mapAsync(string => string.toUpperCase()),
423466
* joinAsync(`, `),
424467
* ),
425468
* )
426-
* //=> sloth, more sloth, even more sloth
469+
* //=> SLOTH, MORE SLOTH, EVEN MORE SLOTH
427470
* ```
428471
*
429472
* @category Collections
@@ -437,21 +480,27 @@ export const joinAsync: {
437480
}
438481

439482
/**
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`.
442485
*
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.
445491
*
446492
* @example
447-
* ```js
493+
* ```js playground
494+
* import { asConcur, joinConcur, mapConcur, pipe } from 'lfi'
495+
*
448496
* console.log(
449497
* await pipe(
450498
* asConcur([`sloth`, `more sloth`, `even more sloth`]),
499+
* mapConcur(string => string.toUpperCase()),
451500
* joinConcur(`, `),
452501
* ),
453502
* )
454-
* //=> sloth, more sloth, even more sloth
503+
* //=> SLOTH, MORE SLOTH, EVEN MORE SLOTH
455504
* ```
456505
*
457506
* @category Collections

0 commit comments

Comments
 (0)