data-cycle-0.1.2: a cyclic doubly linked list

Data.Cycle

Synopsis

Documentation

data Cycle a Source

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.

Instances

 Monad Cycle Functor Cycle Applicative Cycle Alternative Cycle Eq a => Eq (Cycle a) Show a => Show (Cycle a) Monoid (Cycle a) Collection (Cycle a) a Unfoldable (Cycle a) a Sequence (Cycle a) a Foldable (Cycle a) a Indexed (Cycle a) Int a

goLeft :: Cycle a -> Cycle aSource

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

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`).

getValue :: Cycle a -> aSource

Get the value at the current position. `error` if `null c`.

leftValue :: Cycle a -> aSource

Get value on the left. `error` if `null c`.

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.

zipCycle :: Cycle a -> Cycle b -> Cycle (a, b)Source

``` zipCycle = zipCycleWith (,)
```

zipCycleWith :: (a -> b -> c) -> Cycle a -> Cycle b -> Cycle cSource

Combine two cycles by applying a binary function to all element pairs. Like `zipWith`.