cycle package:protolude

cycle ties a finite list into a circular one, or equivalently, the infinite repetition of the original list. It is the identity on infinite lists.

Examples

>>> cycle []
*** Exception: Prelude.cycle: empty list
>>> take 10 (cycle [42])
[42,42,42,42,42,42,42,42,42,42]
>>> take 10 (cycle [2, 5, 7])
[2,5,7,2,5,7,2,5,7,2]
>>> take 1 (cycle (42 : undefined))
[42]
A generalization of cycle to an arbitrary Semigroup. May fail to terminate for some values in some semigroups.

Examples

>>> take 10 $ cycle1 [1, 2, 3]
[1,2,3,1,2,3,1,2,3,1]
>>> cycle1 (Right 1)
Right 1
>>> cycle1 (Left 1)
* hangs forever *