Zipper.md

March 30, 2016 ยท View on GitHub

Module Data.List.Zipper

Zipper

data Zipper a
  = Zipper (List a) a (List a)
Instances
(Show a) => Show (Zipper a)
(Eq a) => Eq (Zipper a)
Functor Zipper
Extend Zipper
Comonad Zipper
Foldable Zipper
Traversable Zipper

up

up :: forall a. Zipper a -> Maybe (Zipper a)

O(1) Move one step closer to the start of the Zipper. This is the inverse of down where their composition is defined (while not at one of the ends of the Zipper).

down

down :: forall a. Zipper a -> Maybe (Zipper a)

O(1) Move one step closer to the end of the Zipper. This is the inverse of up where their composition is defined (while not at one of the ends of the Zipper).

beginning

beginning :: forall a. Zipper a -> Zipper a

O(n) Go to the beginning of the Zipper. This should be an idempotent operation of the Zipper (once at the beginning, moving to the head will not change the focus).

end

end :: forall a. Zipper a -> Zipper a

O(n) Go to the end of the Zipper. This should be an idempotent operation of the Zipper (once at the end, moving to the head will not change the focus).

toUnfoldable

toUnfoldable :: forall a f. (Unfoldable f) => Zipper a -> f a

Convert a Zipper into any type with an Unfoldable instance. Assuming that the definition of unfoldr is O(n), the unfolding will be O(2 * l + r) where l is the length of the lefthand/top list of the Zipper and r is the length of the righthand/bottom.

fromFoldable

fromFoldable :: forall a f. (Foldable f) => f a -> Maybe (Zipper a)

Convert any type with a Foldable instance into a Zipper with the possibility for failure (in the case of an empty Foldable). Assuming the definition of foldr is O(n), the folding will also be O(n).