Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data 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)
- zipper :: Cofree f a -> Zipper i f a
- fromRecursive :: Recursive t => t -> Zipper i (Base t) ()
- tagged :: Recursive t => (t -> a) -> t -> Zipper i (Base t) a
- down :: Idx i f a => i -> Zipper i f a -> Maybe (Zipper i f a)
- up :: Idx i f a => Zipper i f a -> Maybe (Zipper i f a)
- sibling :: Idx i f a => i -> Zipper i f a -> Maybe (Zipper i f a)
- tug :: (a -> Maybe a) -> a -> a
- rezip :: Idx i f a => Zipper i f a -> Cofree f a
- flatten :: (Corecursive f, Idx i (Base f) a) => Zipper i (Base f) a -> f
- fold :: (Functor f, Idx i f a) => (a -> f r -> r) -> Zipper i f a -> r
- focus :: Zipper i f a -> Cofree f a
- branches :: Zipper i f a -> f (Cofree f a)
- currentIndex :: Zipper i f a -> Maybe i
- focus_ :: Lens' (Zipper i f a) a
- unwrapped_ :: Lens' (Zipper i f a) (Cofree f a)
- branches_ :: Lens' (Zipper i f a) (f (Cofree f a))
- children_ :: Traversable f => Traversal' (Zipper i f a) (Cofree f a)
- ichildren_ :: TraversableWithIndex i f => IndexedTraversal' i (Zipper i f a) (Cofree f a)
Core type
data Zipper i (f :: * -> *) a Source #
The core zipper type
Instances
Functor f => Functor (Zipper i f) Source # | |
(Eq1 f, Eq i, Eq a) => Eq (Zipper i f a) Source # | |
(Ord1 f, Ord i, Ord a) => Ord (Zipper i f a) Source # | |
Defined in Zipper.Recursive.Internal |
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
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
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
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
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.