Function: generate()
Returns an infinite iterable that yields seed
for its first value and then
yields the result of applying fn
to its previously yielded value for every
subsequent value.
Example
console.log(
pipe(
generate(previousValue => previousValue + previousValue, `sloth`),
take(3),
reduce(toArray()),
),
)
//=> [ 'sloth', 'slothsloth', 'slothslothslothsloth' ]
generate(fn)
generate<
Value
>(fn
): (seed
) =>Iterable
<Value
,any
,any
>
Returns an infinite iterable that yields seed
for its first value and then
yields the result of applying fn
to its previously yielded value for every
subsequent value.
Type Parameters
• Value
Parameters
• fn
Returns
Function
Parameters
• seed: Value
Returns
Iterable
<Value
, any
, any
>
Example
console.log(
pipe(
generate(previousValue => previousValue + previousValue, `sloth`),
take(3),
reduce(toArray()),
),
)
//=> [ 'sloth', 'slothsloth', 'slothslothslothsloth' ]
Defined in
generate(fn, seed)
generate<
Value
>(fn
,seed
):Iterable
<Value
,any
,any
>
Returns an infinite iterable that yields seed
for its first value and then
yields the result of applying fn
to its previously yielded value for every
subsequent value.
Type Parameters
• Value
Parameters
• fn
• seed: Value
Returns
Iterable
<Value
, any
, any
>
Example
console.log(
pipe(
generate(previousValue => previousValue + previousValue, `sloth`),
take(3),
reduce(toArray()),
),
)
//=> [ 'sloth', 'slothsloth', 'slothslothslothsloth' ]