An implementation of a zipper-like non-empty list structure that tracks
an index position in the list (the `focus`

).

- data PointedList a = PointedList [a] a [a]
- singleton :: a -> PointedList a
- fromList :: [a] -> Maybe (PointedList a)
- fromListEnd :: [a] -> Maybe (PointedList a)
- focus :: PointedList a -> a
- next :: PointedList a -> Maybe (PointedList a)
- tryNext :: PointedList a -> PointedList a
- previous :: PointedList a -> Maybe (PointedList a)
- tryPrevious :: PointedList a -> PointedList a
- insert :: a -> PointedList a -> PointedList a
- insertLeft :: a -> PointedList a -> PointedList a
- insertRight :: a -> PointedList a -> PointedList a
- delete :: PointedList a -> Maybe (PointedList a)
- deleteLeft :: PointedList a -> Maybe (PointedList a)
- deleteRight :: PointedList a -> Maybe (PointedList a)
- length :: PointedList a -> Int
- atStart :: PointedList a -> Bool
- atEnd :: PointedList a -> Bool
- positions :: PointedList a -> PointedList (PointedList a)
- contextMap :: (PointedList a -> b) -> PointedList a -> PointedList b

# Documentation

data PointedList a Source

The implementation of the pointed list structure which tracks the current position in the list structure.

PointedList [a] a [a] |

Functor PointedList | |

Foldable PointedList | |

Traversable PointedList | |

Eq a => Eq (PointedList a) | |

Ord a => Ord (PointedList a) | |

Show a => Show (PointedList a) |

singleton :: a -> PointedList aSource

Create a `PointedList`

with a single element.

fromList :: [a] -> Maybe (PointedList a)Source

Possibly create a `Just PointedList`

if the provided list has at least one
element; otherwise, return Nothing.

The provided list's head will be the focus of the list, and the rest of list will follow on the right side.

fromListEnd :: [a] -> Maybe (PointedList a)Source

Possibly create a `Just PointedList`

if the provided list has at least one
element; otherwise, return Nothing.

The provided list's last element will be the focus of the list, following the rest of the list in order, to the left.

focus :: PointedList a -> aSource

The focus element of the pointed list.

next :: PointedList a -> Maybe (PointedList a)Source

Possibly move the focus to the next element in the list.

tryNext :: PointedList a -> PointedList aSource

Attempt to move the focus to the next element, or `error`

if there are
no more elements.

previous :: PointedList a -> Maybe (PointedList a)Source

Possibly move the focus to the previous element in the list.

tryPrevious :: PointedList a -> PointedList aSource

Attempt to move the focus to the previous element, or `error`

if there are
no more elements.

insert :: a -> PointedList a -> PointedList aSource

An alias for `insertRight`

.

insertLeft :: a -> PointedList a -> PointedList aSource

Insert an element to the left of the focus, then move the focus to the new element.

insertRight :: a -> PointedList a -> PointedList aSource

Insert an element to the right of the focus, then move the focus to the new element.

delete :: PointedList a -> Maybe (PointedList a)Source

An alias of `deleteRight`

.

deleteLeft :: PointedList a -> Maybe (PointedList a)Source

Possibly delete the element at the focus, then move the element on the
left to the focus. If no element is on the left, focus on the element to
the right. If the deletion will cause the list to be empty, return
`Nothing`

.

deleteRight :: PointedList a -> Maybe (PointedList a)Source

Possibly delete the element at the focus, then move the element on the
right to the focus. If no element is on the right, focus on the element to
the left. If the deletion will cause the list to be empty, return
`Nothing`

.

length :: PointedList a -> IntSource

The length of the list.

atStart :: PointedList a -> BoolSource

Whether the focus is the first element.

atEnd :: PointedList a -> BoolSource

Whether the focus is the last element.

positions :: PointedList a -> PointedList (PointedList a)Source

Create a `PointedList`

of variations of the provided `PointedList`

, in
which each element is focused, with the provided `PointedList`

as the
focus of the sets.

contextMap :: (PointedList a -> b) -> PointedList a -> PointedList bSource

Map over the `PointedList`

s created via `positions`

, such that `f`

is
called with each element of the list focused in the provided
`PointedList`

. An example makes this easier to understand:

contextMap atStart (fromJust $ fromList [1..5])