rosezipper-0.2: Generic zipper implementation for Data.Tree

Safe Haskell | Safe-Inferred

Data.Tree.Zipper

Contents

- Context
- Conversions
- Moving around
- Node classification
- Working with the current tree

Synopsis

- data TreePos t a
- class PosType t
- data Empty a
- data Full a
- before :: PosType t => TreePos t a -> Forest a
- after :: PosType t => TreePos t a -> Forest a
- forest :: PosType t => TreePos t a -> Forest a
- tree :: TreePos Full a -> Tree a
- label :: TreePos Full a -> a
- parents :: PosType t => TreePos t a -> [(Forest a, a, Forest a)]
- fromTree :: Tree a -> TreePos Full a
- fromForest :: Forest a -> TreePos Empty a
- toForest :: PosType t => TreePos t a -> Forest a
- toTree :: TreePos Full a -> Tree a
- parent :: PosType t => TreePos t a -> Maybe (TreePos Full a)
- root :: TreePos Full a -> TreePos Full a
- prevSpace :: TreePos Full a -> TreePos Empty a
- prevTree :: TreePos Empty a -> Maybe (TreePos Full a)
- prev :: PosType t => TreePos t a -> Maybe (TreePos t a)
- first :: TreePos Empty a -> TreePos Empty a
- spaceAt :: Int -> TreePos Empty a -> TreePos Empty a
- nextSpace :: TreePos Full a -> TreePos Empty a
- nextTree :: TreePos Empty a -> Maybe (TreePos Full a)
- next :: PosType t => TreePos t a -> Maybe (TreePos t a)
- last :: TreePos Empty a -> TreePos Empty a
- children :: TreePos Full a -> TreePos Empty a
- firstChild :: TreePos Full a -> Maybe (TreePos Full a)
- lastChild :: TreePos Full a -> Maybe (TreePos Full a)
- childAt :: Int -> TreePos Full a -> Maybe (TreePos Full a)
- isRoot :: PosType t => TreePos t a -> Bool
- isFirst :: PosType t => TreePos t a -> Bool
- isLast :: PosType t => TreePos t a -> Bool
- isLeaf :: TreePos Full a -> Bool
- isContained :: PosType t => TreePos t a -> Bool
- hasChildren :: TreePos Full a -> Bool
- insert :: Tree a -> TreePos Empty a -> TreePos Full a
- delete :: TreePos Full a -> TreePos Empty a
- setTree :: Tree a -> TreePos Full a -> TreePos Full a
- modifyTree :: (Tree a -> Tree a) -> TreePos Full a -> TreePos Full a
- modifyLabel :: (a -> a) -> TreePos Full a -> TreePos Full a
- setLabel :: a -> TreePos Full a -> TreePos Full a

# 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`.

Instances

PosType Full |
PosType Empty |

data Empty a Source

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

Instances

PosType Empty |
Eq (Empty a) |
Read (Empty a) |
Show (Empty a) |

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 -> Bool Source

Are we at the top of the tree?

isFirst :: PosType t => TreePos t a -> Bool Source

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

isLast :: PosType t => TreePos t a -> Bool Source

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

isLeaf :: TreePos Full a -> Bool Source

Are we at the bottom of the tree?

isContained :: PosType t => TreePos t a -> Bool Source

Do we have a parent?

hasChildren :: TreePos Full a -> Bool Source

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.