Function: cache()
cache<
Value
>(iterable
):Iterable
<Value
,any
,any
>
Returns an iterable equivalent to iterable
that iterates over iterable
at
most once by lazily caching the values from the first iteration.
Type Parameters
• Value
Parameters
iterable
Iterable
<Value
, any
, any
>
Returns
Iterable
<Value
, any
, any
>
Example
import { each, cache, pipe } from 'lfi'
const iterable = pipe(
[`sloth`, `lazy`, `sleep`],
each(console.log),
cache,
)
// No output
console.log([...iterable])
//=> sloth
//=> lazy
//=> sleep
//=> [ 'sloth', 'lazy', 'sleep' ]
console.log([...iterable])
//=> [ 'sloth', 'lazy', 'sleep' ]
Since
v2.0.0