Skip to content

Commit 708271f

Browse files
feat(website): add tsdoc playground examples to predicates (#62)
1 parent 457e5a8 commit 708271f

File tree

1 file changed

+216
-36
lines changed

1 file changed

+216
-36
lines changed

src/operations/predicates.d.ts

+216-36
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,21 @@ type PredicateConcur = {
3636
* Like `Array.prototype.every`, but for iterables.
3737
*
3838
* @example
39-
* ```js
39+
* ```js playground
40+
* import { all, pipe } from 'lfi'
41+
*
42+
* console.log(
43+
* pipe(
44+
* [`sloth`, `lazy`, `sleep`],
45+
* all(word => word.includes(`l`)),
46+
* ),
47+
* )
48+
* //=> true
49+
*
4050
* console.log(
4151
* pipe(
42-
* [`sloth`, `more sloth`, `even more sloth`],
43-
* all(string => string.length > 8),
52+
* [`sloth`, `lazy`, `sleep`],
53+
* all(word => word.includes(`s`)),
4454
* ),
4555
* )
4656
* //=> false
@@ -59,11 +69,28 @@ export const all: Predicate
5969
* Like `Array.prototype.every`, but for async iterables.
6070
*
6171
* @example
62-
* ```js
72+
* ```js playground
73+
* import { allAsync, asAsync, pipe } from 'lfi'
74+
*
75+
* const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`
76+
* const getPartsOfSpeech = async word => {
77+
* const response = await fetch(`${API_URL}/${word}`)
78+
* const [{ meanings }] = await response.json()
79+
* return meanings.map(meaning => meaning.partOfSpeech)
80+
* }
81+
*
6382
* console.log(
6483
* await pipe(
65-
* asAsync([`sloth`, `more sloth`, `even more sloth`]),
66-
* allAsync(string => string.length > 8),
84+
* asAsync([`sloth`, `lazy`, `sleep`]),
85+
* allAsync(async word => (await getPartsOfSpeech(word)).includes(`verb`)),
86+
* ),
87+
* )
88+
* //=> true
89+
*
90+
* console.log(
91+
* await pipe(
92+
* asAsync([`sloth`, `lazy`, `sleep`]),
93+
* allAsync(async word => (await getPartsOfSpeech(word)).includes(`noun`)),
6794
* ),
6895
* )
6996
* //=> false
@@ -82,11 +109,28 @@ export const allAsync: PredicateAsync
82109
* Like `Array.prototype.every`, but for concur iterables.
83110
*
84111
* @example
85-
* ```js
112+
* ```js playground
113+
* import { allConcur, asConcur, pipe } from 'lfi'
114+
*
115+
* const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`
116+
* const getPartsOfSpeech = async word => {
117+
* const response = await fetch(`${API_URL}/${word}`)
118+
* const [{ meanings }] = await response.json()
119+
* return meanings.map(meaning => meaning.partOfSpeech)
120+
* }
121+
*
122+
* console.log(
123+
* await pipe(
124+
* asConcur([`sloth`, `lazy`, `sleep`]),
125+
* allConcur(async word => (await getPartsOfSpeech(word)).includes(`verb`)),
126+
* ),
127+
* )
128+
* //=> true
129+
*
86130
* console.log(
87131
* await pipe(
88-
* asConcur([`sloth`, `more sloth`, `even more sloth`]),
89-
* allConcur(string => string.length > 8),
132+
* asConcur([`sloth`, `lazy`, `sleep`]),
133+
* allConcur(async word => (await getPartsOfSpeech(word)).includes(`noun`)),
90134
* ),
91135
* )
92136
* //=> false
@@ -104,14 +148,24 @@ export const allConcur: PredicateConcur
104148
* Like `Array.prototype.some`, but for iterables.
105149
*
106150
* @example
107-
* ```js
151+
* ```js playground
152+
* import { any, pipe } from 'lfi'
153+
*
108154
* console.log(
109155
* pipe(
110-
* [`sloth`, `more sloth`, `even more sloth`],
111-
* any(string => string.length > 8),
156+
* [`sloth`, `lazy`, `sleep`],
157+
* any(word => word.includes(`s`)),
112158
* ),
113159
* )
114160
* //=> true
161+
*
162+
* console.log(
163+
* pipe(
164+
* [`sloth`, `lazy`, `sleep`],
165+
* any(word => word.includes(`x`)),
166+
* ),
167+
* )
168+
* //=> false
115169
* ```
116170
*
117171
* @category Predicates
@@ -127,14 +181,31 @@ export const any: Predicate
127181
* Like `Array.prototype.some`, but for async iterables.
128182
*
129183
* @example
130-
* ```js
184+
* ```js playground
185+
* import { anyAsync, asAsync, pipe } from 'lfi'
186+
*
187+
* const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`
188+
* const getPartsOfSpeech = async word => {
189+
* const response = await fetch(`${API_URL}/${word}`)
190+
* const [{ meanings }] = await response.json()
191+
* return meanings.map(meaning => meaning.partOfSpeech)
192+
* }
193+
*
131194
* console.log(
132195
* await pipe(
133-
* asAsync([`sloth`, `more sloth`, `even more sloth`]),
134-
* anyAsync(string => string.length > 8),
196+
* asAsync([`sloth`, `lazy`, `sleep`]),
197+
* anyAsync(async word => (await getPartsOfSpeech(word)).includes(`noun`)),
135198
* ),
136199
* )
137200
* //=> true
201+
*
202+
* console.log(
203+
* await pipe(
204+
* asAsync([`sloth`, `lazy`, `sleep`]),
205+
* anyAsync(async word => (await getPartsOfSpeech(word)).includes(`adverb`)),
206+
* ),
207+
* )
208+
* //=> false
138209
* ```
139210
*
140211
* @category Predicates
@@ -150,14 +221,31 @@ export const anyAsync: PredicateAsync
150221
* Like `Array.prototype.some`, but for concur iterables.
151222
*
152223
* @example
153-
* ```js
224+
* ```js playground
225+
* import { anyConcur, asConcur, pipe } from 'lfi'
226+
*
227+
* const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`
228+
* const getPartsOfSpeech = async word => {
229+
* const response = await fetch(`${API_URL}/${word}`)
230+
* const [{ meanings }] = await response.json()
231+
* return meanings.map(meaning => meaning.partOfSpeech)
232+
* }
233+
*
154234
* console.log(
155235
* await pipe(
156-
* asConcur([`sloth`, `more sloth`, `even more sloth`]),
157-
* anyConcur(string => string.length > 8),
236+
* asConcur([`sloth`, `lazy`, `sleep`]),
237+
* anyConcur(async word => (await getPartsOfSpeech(word)).includes(`noun`)),
158238
* ),
159239
* )
160240
* //=> true
241+
*
242+
* console.log(
243+
* await pipe(
244+
* asConcur([`sloth`, `lazy`, `sleep`]),
245+
* anyConcur(async word => (await getPartsOfSpeech(word)).includes(`adverb`)),
246+
* ),
247+
* )
248+
* //=> false
161249
* ```
162250
*
163251
* @category Predicates
@@ -170,14 +258,24 @@ export const anyConcur: PredicateConcur
170258
* Otherwise returns `false`.
171259
*
172260
* @example
173-
* ```js
261+
* ```js playground
262+
* import { none, pipe } from 'lfi'
263+
*
174264
* console.log(
175265
* pipe(
176-
* [`sloth`, `more sloth`, `even more sloth`],
177-
* none(string => string.length > 8),
266+
* [`sloth`, `lazy`, `sleep`],
267+
* none(word => word.includes(`s`)),
178268
* ),
179269
* )
180270
* //=> false
271+
*
272+
* console.log(
273+
* pipe(
274+
* [`sloth`, `lazy`, `sleep`],
275+
* none(word => word.includes(`x`)),
276+
* ),
277+
* )
278+
* //=> true
181279
* ```
182280
*
183281
* @category Predicates
@@ -191,14 +289,31 @@ export const none: Predicate
191289
* Otherwise returns a promise that resolves to `false`.
192290
*
193291
* @example
194-
* ```js
292+
* ```js playground
293+
* import { noneAsync, asAsync, pipe } from 'lfi'
294+
*
295+
* const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`
296+
* const getPartsOfSpeech = async word => {
297+
* const response = await fetch(`${API_URL}/${word}`)
298+
* const [{ meanings }] = await response.json()
299+
* return meanings.map(meaning => meaning.partOfSpeech)
300+
* }
301+
*
195302
* console.log(
196303
* await pipe(
197-
* asAsync([`sloth`, `more sloth`, `even more sloth`]),
198-
* noneAsync(string => string.length > 8),
304+
* asAsync([`sloth`, `lazy`, `sleep`]),
305+
* noneAsync(async word => (await getPartsOfSpeech(word)).includes(`noun`)),
199306
* ),
200307
* )
201308
* //=> false
309+
*
310+
* console.log(
311+
* await pipe(
312+
* asAsync([`sloth`, `lazy`, `sleep`]),
313+
* noneAsync(async word => (await getPartsOfSpeech(word)).includes(`adverb`)),
314+
* ),
315+
* )
316+
* //=> true
202317
* ```
203318
*
204319
* @category Predicates
@@ -212,11 +327,28 @@ export const noneAsync: PredicateAsync
212327
* Otherwise returns a promise that resolves to `false`.
213328
*
214329
* @example
215-
* ```js
330+
* ```js playground
331+
* import { noneConcur, asConcur, pipe } from 'lfi'
332+
*
333+
* const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`
334+
* const getPartsOfSpeech = async word => {
335+
* const response = await fetch(`${API_URL}/${word}`)
336+
* const [{ meanings }] = await response.json()
337+
* return meanings.map(meaning => meaning.partOfSpeech)
338+
* }
339+
*
340+
* console.log(
341+
* await pipe(
342+
* asConcur([`sloth`, `lazy`, `sleep`]),
343+
* noneConcur(async word => (await getPartsOfSpeech(word)).includes(`noun`)),
344+
* ),
345+
* )
346+
* //=> true
347+
*
216348
* console.log(
217349
* await pipe(
218-
* asConcur([`sloth`, `more sloth`, `even more sloth`]),
219-
* noneConcur(string => string.length > 8),
350+
* asConcur([`sloth`, `lazy`, `sleep`]),
351+
* noneConcur(async word => (await getPartsOfSpeech(word)).includes(`adverb`)),
220352
* ),
221353
* )
222354
* //=> false
@@ -234,14 +366,24 @@ export const noneConcur: PredicateConcur
234366
* Like `Array.prototype.includes`, but for iterables.
235367
*
236368
* @example
237-
* ```js
369+
* ```js playground
370+
* import { includes, pipe } from 'lfi'
371+
*
238372
* console.log(
239373
* pipe(
240-
* [`sloth`, `more sloth`, `even more sloth`],
241-
* includes(`more sloth`),
374+
* [`sloth`, `lazy`, `sleep`],
375+
* includes(`lazy`),
242376
* ),
243377
* )
244378
* //=> true
379+
*
380+
* console.log(
381+
* pipe(
382+
* [`sloth`, `lazy`, `sleep`],
383+
* includes(`awake`),
384+
* ),
385+
* )
386+
* //=> false
245387
* ```
246388
*
247389
* @category Predicates
@@ -260,14 +402,33 @@ export const includes: {
260402
* Like `Array.prototype.includes`, but for async iterables.
261403
*
262404
* @example
263-
* ```js
405+
* ```js playground
406+
* import { asAsync, flatMapAsync, includesAsync, pipe } from 'lfi'
407+
*
408+
* const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`
409+
* const getPartsOfSpeech = async word => {
410+
* const response = await fetch(`${API_URL}/${word}`)
411+
* const [{ meanings }] = await response.json()
412+
* return meanings.map(meaning => meaning.partOfSpeech)
413+
* }
414+
*
264415
* console.log(
265416
* await pipe(
266-
* asAsync([`sloth`, `more sloth`, `even more sloth`]),
267-
* includesAsync(`more sloth`),
417+
* asAsync([`sloth`, `lazy`, `sleep`]),
418+
* flatMapAsync(getPartsOfSpeech),
419+
* includesAsync(`noun`),
268420
* ),
269421
* )
270422
* //=> true
423+
*
424+
* console.log(
425+
* await pipe(
426+
* asAsync([`sloth`, `lazy`, `sleep`]),
427+
* flatMapAsync(getPartsOfSpeech),
428+
* includesAsync(`adverb`),
429+
* ),
430+
* )
431+
* //=> false
271432
* ```
272433
*
273434
* @category Predicates
@@ -291,14 +452,33 @@ export const includesAsync: {
291452
* Like `Array.prototype.includes`, but for concur iterables.
292453
*
293454
* @example
294-
* ```js
455+
* ```js playground
456+
* import { asConcur, flatMapConcur, includesConcur, pipe } from 'lfi'
457+
*
458+
* const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`
459+
* const getPartsOfSpeech = async word => {
460+
* const response = await fetch(`${API_URL}/${word}`)
461+
* const [{ meanings }] = await response.json()
462+
* return meanings.map(meaning => meaning.partOfSpeech)
463+
* }
464+
*
295465
* console.log(
296466
* await pipe(
297-
* asConcur([`sloth`, `more sloth`, `even more sloth`]),
298-
* includesConcur(`more sloth`),
467+
* asConcur([`sloth`, `lazy`, `sleep`]),
468+
* flatMapConcur(getPartsOfSpeech),
469+
* includesConcur(`noun`),
299470
* ),
300471
* )
301472
* //=> true
473+
*
474+
* console.log(
475+
* await pipe(
476+
* asConcur([`sloth`, `lazy`, `sleep`]),
477+
* flatMapConcur(getPartsOfSpeech),
478+
* includesConcur(`adverb`),
479+
* ),
480+
* )
481+
* //=> false
302482
* ```
303483
*
304484
* @category Predicates

0 commit comments

Comments
 (0)