Cycle
cycle is an iterator operation that repeatedly traverses a source sequence, indefinitely or for a specified number of repetitions.
The Well-Grounded Rubyist, Fourth Edition
cycle is a Ruby Enumerable method that repeatedly traverses an enumerable object's elements, optionally for a specified number of cycles.
- How it is used
- Repeats enumerable traversals for cyclic data generation, reusable enumerators, and values that must outlast a source collection.
- How deep it goes
- Explains bounded and infinite traversal, enumerator resumption, chaining, and nested use, without detailing implementation internals.
- Examples
- Demonstrates repeated key bytes for XOR and nested cycles for constructing a 104-card double deck.
- What you can do after
- Apply it via Ruby's Enumerable and Enumerator APIs to repeat finite traversals or supply an explicitly consumed infinite sequence.
Read how The Well-Grounded Rubyist, Fourth Edition explains cycle →
Clojure: The Essential Reference
cycle is a Clojure function that repeatedly traverses input items in order to produce an unbounded lazy sequence.
- How it is used
- Generates repeating sequential data for composition with functions such as map, concat, reduce, and transduce.
- How deep it goes
- Defines inputs, outputs, laziness, empty-input behavior, and implementation strategy without detailing the Java internals.
- Examples
- Demonstrates bounded cycling, alternating values, traffic-light states, repeated alphabets, and performance-oriented reduction.
- What you can do after
- Apply it via Clojure's cycle function to adapt finite collections into unbounded lazy sequences.
Related concepts
- infinite data structureproduces · An infinite data structure represents or generates an unbounded number of elements, commonly by producing them lazily rather than storing them all.
- generatorkind of · A generator is a computational component or construct that produces data or values from inputs, representations, context, or specified constraints.
- each_entryequivalent to · each_entry is a Ruby enumeration method that yields each element of a collection to a block.
- zipuses · Zip is an operation that combines corresponding elements from multiple iterables or collections into paired or otherwise combined results.
- concatenationalternative to · Concatenation is the operation of joining ordered sequences end to end to form a single sequence.
- cycleimplements · A cycle is a recurring sequence of connected elements or events that returns to an earlier point, forming a loop.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

