- data Zipper a = Zip ![a] ![a]
- empty :: Zipper a
- fromList :: [a] -> Zipper a
- fromListEnd :: [a] -> Zipper a
- toList :: Zipper a -> [a]
- beginp :: Zipper a -> Bool
- endp :: Zipper a -> Bool
- emptyp :: Zipper a -> Bool
- start, end :: Zipper a -> Zipper a
- cursor :: Zipper a -> a
- safeCursor :: Zipper a -> Maybe a
- left :: Zipper a -> Zipper a
- right :: Zipper a -> Zipper a
- insert :: a -> Zipper a -> Zipper a
- delete :: Zipper a -> Zipper a
- push :: a -> Zipper a -> Zipper a
- pop :: Zipper a -> Zipper a
- replace :: a -> Zipper a -> Zipper a
- reversez :: Zipper a -> Zipper a
- foldrz :: (Zipper a -> b -> b) -> b -> Zipper a -> b
- foldlz :: (b -> Zipper a -> b) -> b -> Zipper a -> b
- foldlz' :: (b -> Zipper a -> b) -> b -> Zipper a -> b
- extractz :: Zipper a -> a
- duplicatez :: Zipper a -> Zipper (Zipper a)
- extendz :: (Zipper a -> b) -> Zipper a -> Zipper b
Documentation
Zip ![a] ![a] |
fromList :: [a] -> Zipper aSource
fromList xs
returns a zipper containing the elements of xs,
focused on the first element.
fromListEnd :: [a] -> Zipper aSource
fromListEnd xs
returns a zipper containing the elements of xs,
focused just off the right end of the list.
endp :: Zipper a -> BoolSource
endp z
returns True
if the zipper is at the end.
It is not safe to call cursor
on z
if endp z
returns True
.
emptyp :: Zipper a -> BoolSource
emptyp z
returns True
if the zipper is completely empty.
forall z. emptyp z == beginp z && endp z
cursor z
returns the targeted element in z
.
This function is not total, but the invariant is that
endp z == False
means that you can safely call
cursor z
.
safeCursor :: Zipper a -> Maybe aSource
safeCursor
is like cursor
but total.
left :: Zipper a -> Zipper aSource
left z
returns the zipper with the focus
shifted left one element.
right :: Zipper a -> Zipper aSource
right z
returns the zipper with the focus
shifted right one element; this can move the
cursor off the end.
delete :: Zipper a -> Zipper aSource
delete z
removes the element at the cursor (if any).
Safe to call on an empty zipper.
forall x z. delete (insert x z) == z
push :: a -> Zipper a -> Zipper aSource
push x z
inserts x into the zipper, and advances
the cursor past it.
pop :: Zipper a -> Zipper aSource
pop z
removes the element before the cursor (if any).
Safe to call on an empty zipper.
forall x z. pop (push x z) == z
replace :: a -> Zipper a -> Zipper aSource
replace a z
changes the current element in the zipper
to the passed in value. If there is no current element,
the zipper is unchanged. If you want to add the element
in that case instead, use insert a (delete z)
.
reversez :: Zipper a -> Zipper aSource
reversez z
returns the zipper with the elements in
the reverse order. O(1). The cursor is moved to the
previous element, so if the cursor was at the start,
it's now off the right end, and if it was off the
right end, it's now at the start of the reversed list.
foldrz :: (Zipper a -> b -> b) -> b -> Zipper a -> bSource
foldrz f x zip
calls f
with the zipper focused on
each element in order, starting with the current.
You are guaranteed that f can safely call cursor on
its argument; the zipper won't be at the end.
foldlz :: (b -> Zipper a -> b) -> b -> Zipper a -> bSource
foldlz f x zip
calls f with the zipper focused on
each element in order, starting with the current.
You are guaranteed that f can safely call cursor on
its argument; the zipper won't be at the end.
foldlz' :: (b -> Zipper a -> b) -> b -> Zipper a -> bSource
foldlz'
is foldlz with a strict accumulator
extractz :: Zipper a -> aSource
extractz
, extendz
, and duplicatez
can be used to
implement Copointed and Comonad from category-extras. I didn't
add the instances here so as not to introduce a dependency
on that package.
duplicatez :: Zipper a -> Zipper (Zipper a)Source