cycle -package:relude

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]
cycle xs returns the infinite repetition of xs:
cycle (1 :| [2,3]) = 1 :| [2,3,1,2,3,...]
cycle ties a finite ByteString into a circular one, or equivalently, the infinite repetition of the original ByteString.
cycle ties a finite, non-empty Text into a circular one, or equivalently, the infinite repetition of the original Text.
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.
>>> cycle []
*** Exception: Prelude.cycle: empty list

>>> cycle [42]
[42,42,42,42,42,42,42,42,42,42...

>>> cycle [2, 5, 7]
[2,5,7,2,5,7,2,5,7,2,5,7...
Generalization of cycle to any monoid.
Cycle repeatedly through the layers of a stream, ad inf. This function is functor-general
cycle = forever
>>> rest <- S.print $ S.splitAt 3 $ S.cycle (yield True >> yield False)
True
False
True

>>> S.print $ S.take 3 rest
False
True
False
cycle ties a finite ByteString into a circular one, or equivalently, the infinite repetition of the original ByteString.
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.
cycle ties a finite, non-empty Text into a circular one, or equivalently, the infinite repetition of the original Text.
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.
>>> cycle []
*** Exception: Prelude.cycle: empty list

>>> take 20 $ cycle [42]
[42,42,42,42,42,42,42,42,42,42...

>>> take 20 $ cycle [2, 5, 7]
[2,5,7,2,5,7,2,5,7,2,5,7...
generic variants: cycle or better Semigroup.cycle
cycle ties a finite ByteStream into a circular one, or equivalently, the infinite repetition of the original ByteStream. For an empty bytestring (like return 17) it of course makes an unproductive loop
>>> Q.putStrLn $ Q.take 7 $ Q.cycle  "y\n"
y
y
y
y
Converts a finite list into a circular one
Uses sharing.
cycle xs returns the infinite repetition of xs:
cycle [1,2,3] = Cons 1 (Cons 2 (Cons 3 (Cons 1 (Cons 2 ...