Function repeat

  • Repeats every value specified number of times.

    import {pipe, repeat} from 'iter-ops';

    const i = pipe(
    [1, 2, 3],
    repeat(2)
    );

    console.log(...i); //=> 1, 1, 1, 2, 2, 2, 3, 3, 3

    Type Parameters

    • T

    Parameters

    • count: number

    Returns Operation<T, T>

  • Repeats values while passing predicate test.

    • value - repeated value
    • index - original value index
    • count - repeats count thus far (starts with 0)
    • state - iteration state
    import {pipe, repeat} from 'iter-ops';

    const i = pipe(
    [1, 2, 3, 4, 5, 6, 7],
    repeat((a, idx, c) => a % 2 === 0 && c < 2) // repeat even numbers 2 times
    );

    console.log(...i); //=> 1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 7

    Note that the predicate can only return a Promise inside an asynchronous pipeline, or else the Promise will be treated as a truthy value.

    Type Parameters

    • T

    Parameters

    • cb: ((value: T, index: number, count: number, state: IterationState) => boolean | Promise<boolean>)
        • (value, index, count, state): boolean | Promise<boolean>
        • Parameters

          Returns boolean | Promise<boolean>

    Returns Operation<T, T>