Skip to content

Commit 1d11bc3

Browse files
committed
feat(website): update concur iterable examples
1 parent 2f49f78 commit 1d11bc3

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

website/docs/concepts/concurrent-iterable.mdx

+17-11
Original file line numberDiff line numberDiff line change
@@ -189,26 +189,26 @@ We can iterate over concur iterables:
189189
```js playground
190190
import { asConcur } from 'lfi'
191191

192-
const concurIterable = asConcur([`sleep`, `climb`, `eat`])
192+
const concurIterable = asConcur([`sloth`, `lazy`, `sleep`])
193193

194194
await concurIterable(console.log)
195+
//=> sloth
196+
//=> lazy
195197
//=> sleep
196-
//=> climb
197-
//=> eat
198198
```
199199

200200
We can manually filter and map them:
201201

202202
```js playground
203203
import { asConcur } from 'lfi'
204204

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`])
206208

207209
const transformedConcurIterable = apply =>
208210
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()
212212
if (adjective.length <= 5) {
213213
// Too short!
214214
return
@@ -218,21 +218,27 @@ const transformedConcurIterable = apply =>
218218
})
219219

220220
await transformedConcurIterable(console.log)
221+
// NOTE: This order may change between runs
222+
//=> educated sloth
223+
//=> favorite sleep
221224
```
222225

223226
Or we can use `lfi`'s functions to filter and map them!
224227

225228
```js playground
226229
import { asConcur, filterMapConcur, forEachConcur, pipe } from 'lfi'
227230

231+
const API_URL = `https://random-word-form.herokuapp.com/random/adjective`
232+
228233
await pipe(
229-
asConcur([`sleep`, `climb`, `eat`]),
234+
asConcur([`sloth`, `lazy`, `sleep`]),
230235
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()
234237
return adjective.length <= 5 ? null : `${adjective} ${verb}`
235238
}),
236239
forEachConcur(console.log),
237240
)
241+
// NOTE: This order may change between runs
242+
//=> educated sloth
243+
//=> favorite sleep
238244
```

0 commit comments

Comments
 (0)