Safe Haskell | Safe-Infered |
---|

- data Cycle a
- goLeft :: Cycle a -> Cycle a
- goRight :: Cycle a -> Cycle a
- goLR :: Int -> Cycle a -> Cycle a
- getValue :: Cycle a -> a
- leftValue :: Cycle a -> a
- rightValue :: Cycle a -> a
- nthValue :: Int -> Cycle a -> a
- takeLR :: Int -> Cycle a -> [a]
- dropLR :: Int -> Cycle a -> [a]
- cycleToInfiniteList :: Cycle a -> [a]
- zipCycle :: Cycle a -> Cycle b -> Cycle (a, b)
- zipCycleWith :: (a -> b -> c) -> Cycle a -> Cycle b -> Cycle c

# Documentation

A cyclic doubly linked list.

To create a new Cycle, use
`fromList`

, `fromFoldable`

or any of
the insertion functions from `Unfoldable`

. Elements
are inserted in front of the current position.

To get the length of the list, use `size`

.
To extract all cycle elements, use `toList`

. You can
also create an infinite list with `cycleToInfiniteList`

.

`take`

, `drop`

and `splitAt`

also accept negative values for working backwards (see `takeLR`

and `dropLR`

for details).

In general, any function `f`

working on
`[a]`

can be adapted for `Cycle a`

by writing `fromList . f . toList`

.

The `Monad`

, `Functor`

, `Applicative`

, `Alternative`

, `Monoid`

and
`Foldable`

instances work
like the default instances for lists.

goRight :: Cycle a -> Cycle aSource

Move focus to the element on the right of the current position.

goLeft . goRight == id

goLR :: Int -> Cycle a -> Cycle aSource

Move `abs n`

steps to the left (`n < 0`

) or right (`n > 0`

) or don't move
at all (`n == 0`

).

rightValue :: Cycle a -> aSource

Get value on the right. `error`

if `null c`

.

nthValue :: Int -> Cycle a -> aSource

Get nth value to the left (`n < 0`

) or right (`n > 0`

) or
the current value (`n == 0`

). `error`

if `null c`

.

nthValue = flip (!)

takeLR :: Int -> Cycle a -> [a]Source

Take `abs n`

values starting at the current one and moving
to the right (`n > 0`

) or left (`n < 0`

). `n`

can be arbitrary
big.

take n = fromList . takeLR n

dropLR :: Int -> Cycle a -> [a]Source

Drop `abs n`

values starting at the current one and moving
to the right (`n > 0`

) or left (`n < 0`

). `n`

can be arbitrary
big.

drop n = fromList . dropLR n

cycleToInfiniteList :: Cycle a -> [a]Source

Convert to an infinite list starting with the current value and moving to the right.