@@ -36,11 +36,21 @@ type PredicateConcur = {
36
36
* Like `Array.prototype.every`, but for iterables.
37
37
*
38
38
* @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
+ *
40
50
* console.log(
41
51
* pipe(
42
- * [`sloth`, `more sloth `, `even more sloth `],
43
- * all(string => string.length > 8 ),
52
+ * [`sloth`, `lazy `, `sleep `],
53
+ * all(word => word.includes(`s`) ),
44
54
* ),
45
55
* )
46
56
* //=> false
@@ -59,11 +69,28 @@ export const all: Predicate
59
69
* Like `Array.prototype.every`, but for async iterables.
60
70
*
61
71
* @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
+ *
63
82
* console.log(
64
83
* 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`)),
67
94
* ),
68
95
* )
69
96
* //=> false
@@ -82,11 +109,28 @@ export const allAsync: PredicateAsync
82
109
* Like `Array.prototype.every`, but for concur iterables.
83
110
*
84
111
* @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
+ *
86
130
* console.log(
87
131
* 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`) ),
90
134
* ),
91
135
* )
92
136
* //=> false
@@ -104,14 +148,24 @@ export const allConcur: PredicateConcur
104
148
* Like `Array.prototype.some`, but for iterables.
105
149
*
106
150
* @example
107
- * ```js
151
+ * ```js playground
152
+ * import { any, pipe } from 'lfi'
153
+ *
108
154
* console.log(
109
155
* pipe(
110
- * [`sloth`, `more sloth `, `even more sloth `],
111
- * any(string => string.length > 8 ),
156
+ * [`sloth`, `lazy `, `sleep `],
157
+ * any(word => word.includes(`s`) ),
112
158
* ),
113
159
* )
114
160
* //=> true
161
+ *
162
+ * console.log(
163
+ * pipe(
164
+ * [`sloth`, `lazy`, `sleep`],
165
+ * any(word => word.includes(`x`)),
166
+ * ),
167
+ * )
168
+ * //=> false
115
169
* ```
116
170
*
117
171
* @category Predicates
@@ -127,14 +181,31 @@ export const any: Predicate
127
181
* Like `Array.prototype.some`, but for async iterables.
128
182
*
129
183
* @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
+ *
131
194
* console.log(
132
195
* 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`) ),
135
198
* ),
136
199
* )
137
200
* //=> 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
138
209
* ```
139
210
*
140
211
* @category Predicates
@@ -150,14 +221,31 @@ export const anyAsync: PredicateAsync
150
221
* Like `Array.prototype.some`, but for concur iterables.
151
222
*
152
223
* @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
+ *
154
234
* console.log(
155
235
* 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`) ),
158
238
* ),
159
239
* )
160
240
* //=> 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
161
249
* ```
162
250
*
163
251
* @category Predicates
@@ -170,14 +258,24 @@ export const anyConcur: PredicateConcur
170
258
* Otherwise returns `false`.
171
259
*
172
260
* @example
173
- * ```js
261
+ * ```js playground
262
+ * import { none, pipe } from 'lfi'
263
+ *
174
264
* console.log(
175
265
* pipe(
176
- * [`sloth`, `more sloth `, `even more sloth `],
177
- * none(string => string.length > 8 ),
266
+ * [`sloth`, `lazy `, `sleep `],
267
+ * none(word => word.includes(`s`) ),
178
268
* ),
179
269
* )
180
270
* //=> false
271
+ *
272
+ * console.log(
273
+ * pipe(
274
+ * [`sloth`, `lazy`, `sleep`],
275
+ * none(word => word.includes(`x`)),
276
+ * ),
277
+ * )
278
+ * //=> true
181
279
* ```
182
280
*
183
281
* @category Predicates
@@ -191,14 +289,31 @@ export const none: Predicate
191
289
* Otherwise returns a promise that resolves to `false`.
192
290
*
193
291
* @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
+ *
195
302
* console.log(
196
303
* 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`) ),
199
306
* ),
200
307
* )
201
308
* //=> 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
202
317
* ```
203
318
*
204
319
* @category Predicates
@@ -212,11 +327,28 @@ export const noneAsync: PredicateAsync
212
327
* Otherwise returns a promise that resolves to `false`.
213
328
*
214
329
* @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
+ *
216
348
* console.log(
217
349
* 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`) ),
220
352
* ),
221
353
* )
222
354
* //=> false
@@ -234,14 +366,24 @@ export const noneConcur: PredicateConcur
234
366
* Like `Array.prototype.includes`, but for iterables.
235
367
*
236
368
* @example
237
- * ```js
369
+ * ```js playground
370
+ * import { includes, pipe } from 'lfi'
371
+ *
238
372
* console.log(
239
373
* pipe(
240
- * [`sloth`, `more sloth `, `even more sloth `],
241
- * includes(`more sloth `),
374
+ * [`sloth`, `lazy `, `sleep `],
375
+ * includes(`lazy `),
242
376
* ),
243
377
* )
244
378
* //=> true
379
+ *
380
+ * console.log(
381
+ * pipe(
382
+ * [`sloth`, `lazy`, `sleep`],
383
+ * includes(`awake`),
384
+ * ),
385
+ * )
386
+ * //=> false
245
387
* ```
246
388
*
247
389
* @category Predicates
@@ -260,14 +402,33 @@ export const includes: {
260
402
* Like `Array.prototype.includes`, but for async iterables.
261
403
*
262
404
* @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
+ *
264
415
* console.log(
265
416
* 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`),
268
420
* ),
269
421
* )
270
422
* //=> true
423
+ *
424
+ * console.log(
425
+ * await pipe(
426
+ * asAsync([`sloth`, `lazy`, `sleep`]),
427
+ * flatMapAsync(getPartsOfSpeech),
428
+ * includesAsync(`adverb`),
429
+ * ),
430
+ * )
431
+ * //=> false
271
432
* ```
272
433
*
273
434
* @category Predicates
@@ -291,14 +452,33 @@ export const includesAsync: {
291
452
* Like `Array.prototype.includes`, but for concur iterables.
292
453
*
293
454
* @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
+ *
295
465
* console.log(
296
466
* 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`),
299
470
* ),
300
471
* )
301
472
* //=> true
473
+ *
474
+ * console.log(
475
+ * await pipe(
476
+ * asConcur([`sloth`, `lazy`, `sleep`]),
477
+ * flatMapConcur(getPartsOfSpeech),
478
+ * includesConcur(`adverb`),
479
+ * ),
480
+ * )
481
+ * //=> false
302
482
* ```
303
483
*
304
484
* @category Predicates
0 commit comments