| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Brassica.SoundChange.Apply.Internal.MultiZipper
Description
Warning: This module is internal, and does not follow the Package Versioning Policy. It may be useful for extending Brassica, but be prepared to track development closely if you import this module.
Synopsis
- data MultiZipper t a
- fromListStart :: [a] -> MultiZipper t a
- fromListPos :: [a] -> Int -> Maybe (MultiZipper t a)
- toList :: MultiZipper t a -> [a]
- curPos :: MultiZipper t a -> Int
- atStart :: MultiZipper t a -> Bool
- atEnd :: MultiZipper t a -> Bool
- atBoundary :: MultiZipper t a -> Bool
- value :: MultiZipper t a -> Maybe a
- valueN :: Int -> MultiZipper t a -> Maybe ([a], MultiZipper t a)
- locationOf :: Ord t => t -> MultiZipper t a -> Maybe Int
- yank :: (a -> Maybe b) -> MultiZipper t a -> Maybe b
- move :: Int -> MultiZipper t a -> Maybe (MultiZipper t a)
- fwd :: MultiZipper t a -> Maybe (MultiZipper t a)
- bwd :: MultiZipper t a -> Maybe (MultiZipper t a)
- consume :: MultiZipper t a -> Maybe (a, MultiZipper t a)
- seek :: Ord t => t -> MultiZipper t a -> Maybe (MultiZipper t a)
- toBeginning :: MultiZipper t a -> MultiZipper t a
- toEnd :: MultiZipper t a -> MultiZipper t a
- insert :: a -> MultiZipper t a -> MultiZipper t a
- insertMany :: [a] -> MultiZipper t a -> MultiZipper t a
- zap :: (a -> Maybe a) -> MultiZipper t a -> MultiZipper t a
- tag :: Ord t => t -> MultiZipper t a -> MultiZipper t a
- tagAt :: Ord t => t -> Int -> MultiZipper t a -> Maybe (MultiZipper t a)
- query :: Ord t => MultiZipper t a -> [t]
- untag :: MultiZipper t a -> MultiZipper t a
- untagWhen :: (t -> Bool) -> MultiZipper t a -> MultiZipper t a
- delete :: Ord t => (t, t) -> MultiZipper t a -> Maybe (MultiZipper t a)
- extend :: (MultiZipper t a -> b) -> MultiZipper t a -> MultiZipper t b
- extend' :: (MultiZipper t a -> b) -> MultiZipper t a -> MultiZipper t b
Documentation
data MultiZipper t a Source #
A MultiZipper is a list zipper (list+current index), with the
addition of ‘tags’ which can be assigned to indices in the
list. Any tag may be assigned to any index, with the restriction
that two different indices may not be tagged with the same
tag. This sort of data structure is useful for certain algorithms,
where it can be convenient to use tags to save positions in the
list and then return back to them later.
(One subtlety: unlike most list zipper implementations, a
MultiZipper positioned at the ‘end’ of a list is actually at
positioned at the index one past the end of the list, rather than
at the last element of the list. Although this makes some functions
slightly more complex — most notably, value becomes non-total —
it makes other algorithms simpler. For instance, this lets
functions processing a MultiZipper to process a portion of the
MultiZipper and then move to the next element immediately after
the processed portion, allowing another function to be run to
process the next part of the MultiZipper.)
Instances
Conversion
fromListStart :: [a] -> MultiZipper t a Source #
Convert a list to a MultiZipper positioned at the start of that
list.
fromListPos :: [a] -> Int -> Maybe (MultiZipper t a) Source #
Convert a list to a MultiZipper at a specific position in the
list. Returns Nothing if the index is invalid.
toList :: MultiZipper t a -> [a] Source #
Get the list stored in a MultiZipper.
Querying
curPos :: MultiZipper t a -> Int Source #
The current position of the MultiZipper.
atStart :: MultiZipper t a -> Bool Source #
Determine whether the MultiZipper is positioned at the start of
its list.
atEnd :: MultiZipper t a -> Bool Source #
Determine whether the MultiZipper is positioned at the end of
its list.
atBoundary :: MultiZipper t a -> Bool Source #
Determine whether the MultiZipper is positioned at the start or
end of its list.
value :: MultiZipper t a -> Maybe a Source #
The element at the current position of the MultiZipper. Returns
Nothing if the MultiZipper is positioned ‘at the end of the
list’ (recall this actually means that the MultiZipper is
positioned after the last element of its list).
valueN :: Int -> MultiZipper t a -> Maybe ([a], MultiZipper t a) Source #
valueN n mz returns the next n elements of mz starting from
the current position, as well as returning a new MultiZipper
positioned past the end of those n elements. (So running
valueN m and then valueN n would return the next m+n
elements.) Returns Nothing if this would move the position of the
MultiZipper past the end of the list.
locationOf :: Ord t => t -> MultiZipper t a -> Maybe Int Source #
Given a tag, return its position
yank :: (a -> Maybe b) -> MultiZipper t a -> Maybe b Source #
Find first element before point which returns Just when
queried, if any, returning the result of the query function.
Movement
move :: Int -> MultiZipper t a -> Maybe (MultiZipper t a) Source #
move n mz will move the position of mz by n forward (if
n>0) or by -n backward (if n<0). Returns Nothing if this would
cause the MultiZipper to move after the end or before the
beginning of the list.
fwd :: MultiZipper t a -> Maybe (MultiZipper t a) Source #
Move one position forward if possible, otherwise return Nothing.
bwd :: MultiZipper t a -> Maybe (MultiZipper t a) Source #
Move one position backwards if possible, otherwise return Nothing.
consume :: MultiZipper t a -> Maybe (a, MultiZipper t a) Source #
If possible, move one position forward, returning the value moved over
seek :: Ord t => t -> MultiZipper t a -> Maybe (MultiZipper t a) Source #
Move the MultiZipper to be at the specified tag. Returns
Nothing if that tag is not present.
toBeginning :: MultiZipper t a -> MultiZipper t a Source #
Move to the beginning of the MultiZipper.
toEnd :: MultiZipper t a -> MultiZipper t a Source #
Move to the end of the MultiZipper.
Modification
insert :: a -> MultiZipper t a -> MultiZipper t a Source #
Insert a new element at point and move forward by one position.
insertMany :: [a] -> MultiZipper t a -> MultiZipper t a Source #
Insert multiple elements at point and move after them. A simple
wrapper around insert.
zap :: (a -> Maybe a) -> MultiZipper t a -> MultiZipper t a Source #
Modify the first element before point to which the modification
function returns Just.
tag :: Ord t => t -> MultiZipper t a -> MultiZipper t a Source #
Set a tag at the current position.
tagAt :: Ord t => t -> Int -> MultiZipper t a -> Maybe (MultiZipper t a) Source #
Set a tag at a given position if possible, otherwise return Nothing.
query :: Ord t => MultiZipper t a -> [t] Source #
Get all tags at the current position
untag :: MultiZipper t a -> MultiZipper t a Source #
Remove all tags.
untagWhen :: (t -> Bool) -> MultiZipper t a -> MultiZipper t a Source #
Remove tags satisfying predicate
Arguments
| :: Ord t | |
| => (t, t) | Selected tags. Note that the resulting interval will be [inclusive, exclusive). |
| -> MultiZipper t a | |
| -> Maybe (MultiZipper t a) |
Delete the portion of a MultiZipper between the selected tags.
Returns Nothing if a nonexistent tag is selected, else returns
the modified MultiZipper.
extend :: (MultiZipper t a -> b) -> MultiZipper t a -> MultiZipper t b Source #
Given a function to compute a value from a MultiZipper starting
at a particular point, apply that function to all possible starting
points and collect the results. Tags are left unchanged.
(Note: this is really just the same extend method as in the
Comonad typeclass, although MultiZipper wouldn’t be a lawful
comonad.)
extend' :: (MultiZipper t a -> b) -> MultiZipper t a -> MultiZipper t b Source #
Like extend, but includes the end position of the zipper, thus
increasing the MultiZipper length by one when called.