Prelude API
    Preparing search index...

    Function cycle

    • Creates an infinite generator that repeatedly cycles through the values of an iterable. If the input iterable is empty, returns an empty generator.

      Type Parameters

      • T

        Type of elements in the iterable

      Parameters

      • values: Iterable<T>

        The source iterable to cycle through

      Returns Generator<T>

      An infinite generator that cycles through the input values

      Values from the source iterable, repeatedly cycling through them indefinitely

      // Create a cycling generator of numbers
      const cycled = cycle([1, 2, 3])
      const first6Values = []
      for (let i = 0; i < 6; i++) {
      first6Values.push(cycled.next().value)
      }
      // Result: [1, 2, 3, 1, 2, 3]
      // Create a cycling generator from a string
      const letters = cycle("ABC")
      const first5Values = []
      for (let i = 0; i < 5; i++) {
      first5Values.push(letters.next().value)
      }
      // Result: ['A', 'B', 'C', 'A', 'B']