Aller au contenu principal

iterate()

iterate<T>(seed, f): Iterable<T>

Creates an infinite iterable by repeatedly applying a function to a seed.

Produces: seed, f(seed), f(f(seed)), ...


Type Parameters

T: T

The element type


Parameters

seed: T

The initial value

f: (value) => T

The function to apply repeatedly


Returns: Iterable<T>

An infinite lazy Iterable


Since

2.4.0


Example

// Powers of 2
toArray(take(5)(iterate(1, (n) => n * 2))); // [1, 2, 4, 8, 16]