rosezipper-0.1: Generic zipper implementation for Data.Tree

Data.Tree.Zipper

Contents

Synopsis

Documentation

data TreeLoc a Source

A position within a Tree.

Constructors

Loc 

Fields

tree :: Tree a

The currently selected tree.

lefts :: Forest a

Siblings on the left, closest first.

rights :: Forest a

Siblings on the right, closest first.

parents :: [(Forest a, a, Forest a)]

The contexts of the parents for this location.

Instances

Eq a => Eq (TreeLoc a) 
Read a => Read (TreeLoc a) 
Show a => Show (TreeLoc a) 

Conversions

fromTree :: Tree a -> TreeLoc aSource

A location corresponding to the root of the given tree.

fromForest :: Forest a -> Maybe (TreeLoc a)Source

The location of the first tree in a forest.

toForest :: TreeLoc a -> Forest aSource

Computes the forest containing this location.

toTree :: TreeLoc a -> Tree aSource

Computes the tree containing this location.

Moving around

parent :: TreeLoc a -> Maybe (TreeLoc a)Source

The parent of the given location.

root :: TreeLoc a -> TreeLoc aSource

The top-most parent of the given location.

getChild :: Int -> TreeLoc a -> Maybe (TreeLoc a)Source

The child with the given index (starting from 0).

findChild :: (Tree a -> Bool) -> TreeLoc a -> Maybe (TreeLoc a)Source

The first child that satisfies a predicate.

firstChild :: TreeLoc a -> Maybe (TreeLoc a)Source

The first child of the given location.

lastChild :: TreeLoc a -> Maybe (TreeLoc a)Source

The last child of the given location.

left :: TreeLoc a -> Maybe (TreeLoc a)Source

The left sibling of the given location.

right :: TreeLoc a -> Maybe (TreeLoc a)Source

The right sibling of the given location.

Node classification

isRoot :: TreeLoc a -> BoolSource

Are we at the top of the tree?

isFirst :: TreeLoc a -> BoolSource

Are we at the left end of the the tree?

isLast :: TreeLoc a -> BoolSource

Are we at the right end of the tree?

isLeaf :: TreeLoc a -> BoolSource

Are we at the bottom of the tree?

isChild :: TreeLoc a -> BoolSource

Do we have a parent?

hasChildren :: TreeLoc a -> BoolSource

Do we have children?

Tree-specific mutation

insertLeft :: Tree a -> TreeLoc a -> TreeLoc aSource

Insert a tree to the left of the current position. The new tree becomes the current tree.

insertRight :: Tree a -> TreeLoc a -> TreeLoc aSource

Insert a tree to the right of the current position. The new tree becomes the current tree.

delete :: TreeLoc a -> Maybe (TreeLoc a)Source

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 aSource

Change the current tree.

modifyTree :: (Tree a -> Tree a) -> TreeLoc a -> TreeLoc aSource

Modify the current tree.

modifyLabel :: (a -> a) -> TreeLoc a -> TreeLoc aSource

Modify the label at the current node.

setLabel :: a -> TreeLoc a -> TreeLoc aSource

Change the label at the current node.