• Internal

    Create a new generator that yields values generated by applying the function to the previous value starting with the initial value.

    Type Parameters

    • T

      The type of the value to yield

    Parameters

    • init: T

      Initial value

    • fn: UnaryOperator<T>

      Function to apply to the previous value to get the next value

    Returns Generator<T>

    A new generator that yields the value n times.

    Example

    const gen = iterate(1, (x) => x * 2);
    console.log([...take(gen, 5)]); // [1, 2, 4, 8, 16]

Generated using TypeDoc