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

Zipper.Recursive.Internal

Synopsis

Documentation

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.

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

The core zipper type

Constructors

Zipper 

Fields

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 #

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

Get the location of the current selection within its parent if we have one.

O(1)

currentPath :: Zipper i f a -> [i] Source #

Get the path to the current value from the root of the structure.

@O(depth)

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

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

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.

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)

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)

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

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.

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

Get the base-functor at the current location.

O(1)

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

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

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)