Skip to main content

iterate

Callable

  • iterate<T>(x: T, f: (x: T, i: number) => T): Traversable<T>

  • Creates a stateful generator that iterates over a predicates output given an initial value.

    Example

    collect(take(iterate('foo', (str) => `${str}bar`), 4))
    // => [
    // "foo",
    // "foobar",
    // "foobarbar",
    // "foobarbarbar",
    // ]

    Type parameters

    • T

      The element type.

    Parameters

    • x: T

      The initial value to start iterating with.

    • f: (x: T, i: number) => T

      The lambda that will be used to iterate with.

    Returns Traversable<T>

    The iterate generator.