Variable: indexAsync()
const
indexAsync: <Value
>(asyncIterable
) =>AsyncIterable
<[number
,Value
]>
Defined in: transforms.d.ts:491
Returns an async iterable equivalent to asyncIterable
except each value of
asyncIterable
is placed in an entry containing the value's 0-based index in
the iteration order followed by the value itself.
Type Parameters
Value
Value
Parameters
asyncIterable
AsyncIterable
<Value
>
Returns
AsyncIterable
<[number
, Value
]>
Example
import { asAsync, indexAsync, joinAsync, mapAsync, pipe } from 'lfi'
const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`
console.log(
await pipe(
asAsync([`sloth`, `lazy`, `sleep`]),
mapAsync(async word => {
const response = await fetch(`${API_URL}/${word}`)
return (await response.json())[0].phonetic
}),
indexAsync,
mapAsync(([index, word]) => `${index + 1}. ${word}`),
joinAsync(`\n`),
),
)
//=> 1. /slɑθ/
//=> 2. /ˈleɪzi/
//=> 3. /sliːp/
Since
v2.0.0