@@ -189,26 +189,26 @@ We can iterate over concur iterables:
189
189
``` js playground
190
190
import { asConcur } from ' lfi'
191
191
192
- const concurIterable = asConcur ([` sleep ` , ` climb ` , ` eat ` ])
192
+ const concurIterable = asConcur ([` sloth ` , ` lazy ` , ` sleep ` ])
193
193
194
194
await concurIterable (console .log )
195
+ // => sloth
196
+ // => lazy
195
197
// => sleep
196
- // => climb
197
- // => eat
198
198
```
199
199
200
200
We can manually filter and map them:
201
201
202
202
``` js playground
203
203
import { asConcur } from ' lfi'
204
204
205
- const concurIterable = asConcur ([` sleep` , ` climb` , ` eat` ])
205
+ const API_URL = ` https://random-word-form.herokuapp.com/random/adjective`
206
+
207
+ const concurIterable = asConcur ([` sloth` , ` lazy` , ` sleep` ])
206
208
207
209
const transformedConcurIterable = apply =>
208
210
concurIterable (async verb => {
209
- const [adjective ] = await (
210
- await fetch (` https://random-word-form.herokuapp.com/random/adjective` )
211
- ).json ()
211
+ const [adjective ] = await (await fetch (API_URL )).json ()
212
212
if (adjective .length <= 5 ) {
213
213
// Too short!
214
214
return
@@ -218,21 +218,27 @@ const transformedConcurIterable = apply =>
218
218
})
219
219
220
220
await transformedConcurIterable (console .log )
221
+ // NOTE: This order may change between runs
222
+ // => educated sloth
223
+ // => favorite sleep
221
224
```
222
225
223
226
Or we can use ` lfi ` 's functions to filter and map them!
224
227
225
228
``` js playground
226
229
import { asConcur , filterMapConcur , forEachConcur , pipe } from ' lfi'
227
230
231
+ const API_URL = ` https://random-word-form.herokuapp.com/random/adjective`
232
+
228
233
await pipe (
229
- asConcur ([` sleep ` , ` climb ` , ` eat ` ]),
234
+ asConcur ([` sloth ` , ` lazy ` , ` sleep ` ]),
230
235
filterMapConcur (async verb => {
231
- const [adjective ] = await (
232
- await fetch (` https://random-word-form.herokuapp.com/random/adjective` )
233
- ).json ()
236
+ const [adjective ] = await (await fetch (API_URL )).json ()
234
237
return adjective .length <= 5 ? null : ` ${ adjective} ${ verb} `
235
238
}),
236
239
forEachConcur (console .log ),
237
240
)
241
+ // NOTE: This order may change between runs
242
+ // => educated sloth
243
+ // => favorite sleep
238
244
```
0 commit comments