rosezipper-0.1: Generic zipper implementation for Data.TreeContentsIndex
Data.Tree.Zipper
Contents
Conversions
Moving around
Node classification
Tree-specific mutation
Working with the current tree
Synopsis
data TreeLoc a = Loc {
tree :: Tree a
lefts :: Forest a
rights :: Forest a
parents :: [(Forest a, a, Forest a)]
}
fromTree :: Tree a -> TreeLoc a
fromForest :: Forest a -> Maybe (TreeLoc a)
toForest :: TreeLoc a -> Forest a
toTree :: TreeLoc a -> Tree a
parent :: TreeLoc a -> Maybe (TreeLoc a)
root :: TreeLoc a -> TreeLoc a
getChild :: Int -> TreeLoc a -> Maybe (TreeLoc a)
findChild :: (Tree a -> Bool) -> TreeLoc a -> Maybe (TreeLoc a)
firstChild :: TreeLoc a -> Maybe (TreeLoc a)
lastChild :: TreeLoc a -> Maybe (TreeLoc a)
left :: TreeLoc a -> Maybe (TreeLoc a)
right :: TreeLoc a -> Maybe (TreeLoc a)
isRoot :: TreeLoc a -> Bool
isFirst :: TreeLoc a -> Bool
isLast :: TreeLoc a -> Bool
isLeaf :: TreeLoc a -> Bool
isChild :: TreeLoc a -> Bool
hasChildren :: TreeLoc a -> Bool
insertLeft :: Tree a -> TreeLoc a -> TreeLoc a
insertRight :: Tree a -> TreeLoc a -> TreeLoc a
insertDownFirst :: Tree a -> TreeLoc a -> TreeLoc a
insertDownLast :: Tree a -> TreeLoc a -> TreeLoc a
insertDownAt :: Int -> Tree a -> TreeLoc a -> Maybe (TreeLoc a)
delete :: TreeLoc a -> Maybe (TreeLoc a)
setTree :: Tree a -> TreeLoc a -> TreeLoc a
modifyTree :: (Tree a -> Tree a) -> TreeLoc a -> TreeLoc a
modifyLabel :: (a -> a) -> TreeLoc a -> TreeLoc a
setLabel :: a -> TreeLoc a -> TreeLoc a
getLabel :: TreeLoc a -> a
Documentation
data TreeLoc a
A position within a Tree.
Constructors
Loc
tree :: Tree aThe currently selected tree.
lefts :: Forest aSiblings on the left, closest first.
rights :: Forest aSiblings on the right, closest first.
parents :: [(Forest a, a, Forest a)]The contexts of the parents for this location.
show/hide Instances
Eq a => Eq (TreeLoc a)
Read a => Read (TreeLoc a)
Show a => Show (TreeLoc a)
Conversions
fromTree :: Tree a -> TreeLoc a
A location corresponding to the root of the given tree.
fromForest :: Forest a -> Maybe (TreeLoc a)
The location of the first tree in a forest.
toForest :: TreeLoc a -> Forest a
Computes the forest containing this location.
toTree :: TreeLoc a -> Tree a
Computes the tree containing this location.
Moving around
parent :: TreeLoc a -> Maybe (TreeLoc a)
The parent of the given location.
root :: TreeLoc a -> TreeLoc a
The top-most parent of the given location.
getChild :: Int -> TreeLoc a -> Maybe (TreeLoc a)
The child with the given index (starting from 0).
findChild :: (Tree a -> Bool) -> TreeLoc a -> Maybe (TreeLoc a)
The first child that satisfies a predicate.
firstChild :: TreeLoc a -> Maybe (TreeLoc a)
The first child of the given location.
lastChild :: TreeLoc a -> Maybe (TreeLoc a)
The last child of the given location.
left :: TreeLoc a -> Maybe (TreeLoc a)
The left sibling of the given location.
right :: TreeLoc a -> Maybe (TreeLoc a)
The right sibling of the given location.
Node classification
isRoot :: TreeLoc a -> Bool
Are we at the top of the tree?
isFirst :: TreeLoc a -> Bool
Are we at the left end of the the tree?
isLast :: TreeLoc a -> Bool
Are we at the right end of the tree?
isLeaf :: TreeLoc a -> Bool
Are we at the bottom of the tree?
isChild :: TreeLoc a -> Bool
Do we have a parent?
hasChildren :: TreeLoc a -> Bool
Do we have children?
Tree-specific mutation
insertLeft :: Tree a -> TreeLoc a -> TreeLoc a
Insert a tree to the left of the current position. The new tree becomes the current tree.
insertRight :: Tree a -> TreeLoc a -> TreeLoc a
Insert a tree to the right of the current position. The new tree becomes the current tree.
insertDownFirst :: Tree a -> TreeLoc a -> TreeLoc a
insertDownLast :: Tree a -> TreeLoc a -> TreeLoc a
insertDownAt :: Int -> Tree a -> TreeLoc a -> Maybe (TreeLoc a)
delete :: TreeLoc a -> Maybe (TreeLoc a)
Delete the current node. The new position is: * the right sibling, or if none * the left sibling, or if none * the parent.
Working with the current tree
setTree :: Tree a -> TreeLoc a -> TreeLoc a
Change the current tree.
modifyTree :: (Tree a -> Tree a) -> TreeLoc a -> TreeLoc a
Modify the current tree.
modifyLabel :: (a -> a) -> TreeLoc a -> TreeLoc a
Modify the label at the current node.
setLabel :: a -> TreeLoc a -> TreeLoc a
Change the label at the current node.
getLabel :: TreeLoc a -> a
Produced by Haddock version 2.3.0