recursive-zipper-0.0.0.0: Zippers over recursive data structures.
Safe HaskellNone
LanguageHaskell2010

Zipper.Recursive

Synopsis

Core type

data Zipper i (f :: * -> *) a Source #

The core zipper type

Instances

Instances details
Functor f => Functor (Zipper i f) Source # 
Instance details

Defined in Zipper.Recursive.Internal

Methods

fmap :: (a -> b) -> Zipper i f a -> Zipper i f b #

(<$) :: a -> Zipper i f b -> Zipper i f a #

(Eq1 f, Eq i, Eq a) => Eq (Zipper i f a) Source # 
Instance details

Defined in Zipper.Recursive.Internal

Methods

(==) :: Zipper i f a -> Zipper i f a -> Bool #

(/=) :: Zipper i f a -> Zipper i f a -> Bool #

(Ord1 f, Ord i, Ord a) => Ord (Zipper i f a) Source # 
Instance details

Defined in Zipper.Recursive.Internal

Methods

compare :: Zipper i f a -> Zipper i f a -> Ordering #

(<) :: Zipper i f a -> Zipper i f a -> Bool #

(<=) :: Zipper i f a -> Zipper i f a -> Bool #

(>) :: Zipper i f a -> Zipper i f a -> Bool #

(>=) :: Zipper i f a -> Zipper i f a -> Bool #

max :: Zipper i f a -> Zipper i f a -> Zipper i f a #

min :: Zipper i f a -> Zipper i f a -> Zipper i f a #

type Idx i f a = (Ixed (f (Cofree f a)), IxValue (f (Cofree f a)) ~ Cofree f a, Index (f (Cofree f a)) ~ i) Source #

Alias for constraints required for many zipper operations.

Constructing Zippers

zipper :: Cofree f a -> Zipper i f a Source #

Create a zipper over a cofree structure

fromRecursive :: Recursive t => t -> Zipper i (Base t) () Source #

Create a zipper from a recursive type, tagging it with ()

tagged :: Recursive t => (t -> a) -> t -> Zipper i (Base t) a Source #

Create a zipper from a recursive type, given a function to generate annotations.

Movement

down :: Idx i f a => i -> Zipper i f a -> Maybe (Zipper i f a) Source #

Select the subtree at the given location. O(1)

up :: Idx i f a => Zipper i f a -> Maybe (Zipper i f a) Source #

Select the parent of the current location. O(1)

sibling :: Idx i f a => i -> Zipper i f a -> Maybe (Zipper i f a) Source #

Move to the sibling which is located at i in its parent. O(1)

@ sibling i = up >=> down i @

tug :: (a -> Maybe a) -> a -> a Source #

A useful combinator for chaining operations which might fail. If an operation fails, the original zipper is returned.

E.g.

>>> tug up z

Folding and flattening

rezip :: Idx i f a => Zipper i f a -> Cofree f a Source #

Re-zip the entire tree. O(d)

flatten :: (Corecursive f, Idx i (Base f) a) => Zipper i (Base f) a -> f Source #

Rezip, forget all tags, and flatten the structure. O(d)

fold :: (Functor f, Idx i f a) => (a -> f r -> r) -> Zipper i f a -> r Source #

Fold a zipper from bottom to top. @O(n)

Getters

focus :: Zipper i f a -> Cofree f a Source #

branches :: Zipper i f a -> f (Cofree f a) Source #

Get the base-functor at the current location. @O(1)

currentIndex :: Zipper i f a -> Maybe i Source #

Get the location of the current selection within its parent if we have one. @O(1)

Optics

focus_ :: Lens' (Zipper i f a) a Source #

Focus the tag at the current position.

unwrapped_ :: Lens' (Zipper i f a) (Cofree f a) Source #

Focus the currently selected sub-tree as a Cofree

branches_ :: Lens' (Zipper i f a) (f (Cofree f a)) Source #

A lens over the base-functor at the current location.

children_ :: Traversable f => Traversal' (Zipper i f a) (Cofree f a) Source #

Traversal over all subtrees of the current location.

ichildren_ :: TraversableWithIndex i f => IndexedTraversal' i (Zipper i f a) (Cofree f a) Source #

Indexed traversal over all subtrees of the current location.