rosezipper-0.2: Generic zipper implementation for Data.Tree

Data.Tree.Zipper

Contents

Synopsis

Documentation

data TreePos t a Source

A position within a Tree. The parameter t inidcates if the position is pointing to a specific tree (if t is Full), or if it is pointing in-between trees (if t is Empty).

Instances

(Eq a, Eq (t a)) => Eq (TreePos t a) 
(Read a, Read (t a)) => Read (TreePos t a) 
(Show a, Show (t a)) => Show (TreePos t a) 

class PosType t Source

Positions may be either Full or Empty.

data Empty a Source

Position which does not point to a tree (e.g., it is between two trees).

Instances

data Full a Source

Position which points to a tree.

Instances

PosType Full 
Eq a => Eq (Full a) 
Read a => Read (Full a) 
Show a => Show (Full a) 

Context

before :: PosType t => TreePos t a -> Forest aSource

Siblings before this position, closest first.

after :: PosType t => TreePos t a -> Forest aSource

Siblings after this position, closest first.

forest :: PosType t => TreePos t a -> Forest aSource

All trees at this location (i.e., the current tree---if any---and its siblings).

tree :: TreePos Full a -> Tree aSource

The selected tree.

label :: TreePos Full a -> aSource

The current label.

parents :: PosType t => TreePos t a -> [(Forest a, a, Forest a)]Source

The contexts of the parents for this position.

Conversions

fromTree :: Tree a -> TreePos Full aSource

A location corresponding to the root of the given tree.

fromForest :: Forest a -> TreePos Empty aSource

The location at the beginning of the forest.

toForest :: PosType t => TreePos t a -> Forest aSource

The forest containing this location.

toTree :: TreePos Full a -> Tree aSource

The tree containing this location.

Moving around

parent :: PosType t => TreePos t a -> Maybe (TreePos Full a)Source

The parent of the given location.

root :: TreePos Full a -> TreePos Full aSource

The top-most parent of the given location.

prevSpace :: TreePos Full a -> TreePos Empty aSource

The space immediately before this location.

prevTree :: TreePos Empty a -> Maybe (TreePos Full a)Source

The tree before this location, if any.

prev :: PosType t => TreePos t a -> Maybe (TreePos t a)Source

The sibling before this location.

first :: TreePos Empty a -> TreePos Empty aSource

The first space in the current forest.

spaceAt :: Int -> TreePos Empty a -> TreePos Empty aSource

The empty space at the given index. The first space is at index 0. For indexes that are negative or too large, we return the first and last position in the tree, respectively.

nextSpace :: TreePos Full a -> TreePos Empty aSource

The space immediately after this location.

nextTree :: TreePos Empty a -> Maybe (TreePos Full a)Source

The tree after this location, if any.

next :: PosType t => TreePos t a -> Maybe (TreePos t a)Source

The sibling after this location.

last :: TreePos Empty a -> TreePos Empty aSource

The last space in the current forest.

children :: TreePos Full a -> TreePos Empty aSource

The location at the beginning of the forest of children.

firstChild :: TreePos Full a -> Maybe (TreePos Full a)Source

The first child of the given location.

lastChild :: TreePos Full a -> Maybe (TreePos Full a)Source

The last child of the given location.

childAt :: Int -> TreePos Full a -> Maybe (TreePos Full a)Source

The child at the given index in the tree. The first child is at index 0.

Node classification

isRoot :: PosType t => TreePos t a -> BoolSource

Are we at the top of the tree?

isFirst :: PosType t => TreePos t a -> BoolSource

Are we the first position (of its kind) in a forest.

isLast :: PosType t => TreePos t a -> BoolSource

Are we the last position (of its kind) in a forest.

isLeaf :: TreePos Full a -> BoolSource

Are we at the bottom of the tree?

isContained :: PosType t => TreePos t a -> BoolSource

Do we have a parent?

hasChildren :: TreePos Full a -> BoolSource

Do we have children?

Working with the current tree

insert :: Tree a -> TreePos Empty a -> TreePos Full aSource

Insert a new tree at the current position.

delete :: TreePos Full a -> TreePos Empty aSource

Remove the tree at the current position.

setTree :: Tree a -> TreePos Full a -> TreePos Full aSource

Change the current tree.

modifyTree :: (Tree a -> Tree a) -> TreePos Full a -> TreePos Full aSource

Modify the current tree.

modifyLabel :: (a -> a) -> TreePos Full a -> TreePos Full aSource

Modify the label at the current node.

setLabel :: a -> TreePos Full a -> TreePos Full aSource

Change the label at the current node.