Skip to main content

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

import { generate, pipe, reduce, take, toArray } from 'lfi'

console.log(
pipe(
`sloth`,
generate(previousValue => `${previousValue} ${previousValue}`),
take(4),
reduce(toArray()),
),
)
//=> [
//=> 'sloth',
//=> 'sloth sloth',
//=> 'sloth sloth sloth sloth',
//=> 'sloth sloth sloth sloth sloth sloth sloth sloth'
//=> ]
Playground

Since

v0.0.1

Call Signature

generate<Value>(fn): (seed) => Iterable<Value, any, any>

Type Parameters

Value

Parameters

fn

(previousValue) => Value

Returns

Function

Parameters

seed

Value

Returns

Iterable<Value, any, any>

Defined in

generators.d.ts:226

Call Signature

generate<Value>(fn, seed): Iterable<Value, any, any>

Type Parameters

Value

Parameters

fn

(previousValue) => Value

seed

Value

Returns

Iterable<Value, any, any>

Defined in

generators.d.ts:227