@mirei/ts-collections
    Preparing search index...

    Function cycle

    • Repeats the sequence the specified number of times, or indefinitely when no count is provided.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • Optionalcount: number

        Optional number of times to repeat the sequence. When omitted, the sequence repeats without end.

      Returns IEnumerable<TElement>

      A sequence that yields the original elements cyclically.

      Thrown when the sequence is empty.

      When count is undefined, consume the result with care because it represents an infinite sequence.

      const numbers = [1, 2, 3];
      const cycled = cycle(numbers, 2).toArray();
      console.log(cycled); // [1, 2, 3, 1, 2, 3]