Skip to main content

Variable: generate()

const generate: {<Value>(fn): (seed) => Iterable<Value>; <Value>(fn, seed): Iterable<Value>; }

Defined in: generators.d.ts:225

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.

Call Signature​

<Value>(fn): (seed) => Iterable<Value>

Type Parameters​

Value​

Value

Parameters​

fn​

(previousValue) => Value

Returns​

(seed): Iterable<Value>

Parameters​

seed​

Value

Returns​

Iterable<Value>

Call Signature​

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

Type Parameters​

Value​

Value

Parameters​

fn​

(previousValue) => Value

seed​

Value

Returns​

Iterable<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