Function: cacheAsync()
cacheAsync<
Value
>(asyncIterable
):AsyncIterable
<Value
,any
,any
>
Returns an async iterable equivalent to asyncIterable
that iterates over
asyncIterable
at most once.
Type Parameters
• Value
Parameters
• asyncIterable: AsyncIterable
<Value
, any
, any
>
Returns
AsyncIterable
<Value
, any
, any
>
Example
const asyncIterable = asAsync([`sloth`, `more sloth`, `even more sloth`])
const asyncIterableWithEffects = eachAsync(console.log, asyncIterable)
const cachedAsyncIterable = cacheAsync(asyncIterableWithEffects)
console.log(await pipe(cachedAsyncIterable, reduceAsync(toArray())))
//=> sloth
//=> more sloth
//=> even more sloth
//=> [ 'sloth', 'more sloth', 'even more sloth' ]
console.log(await pipe(cachedAsyncIterable, reduceAsync(toArray())))
//=> [ 'sloth', 'more sloth', 'even more sloth' ]