Zippy v0.0.1 Zippy.ZForest

Zipper forests are a zipper structure where each node is a list of subtrees.You can iterate over this structure, and thus represent a minimum spanning tree, a DOM, an undo tree, etc. Adding, replacing and deleting operations are constant time.

This module is a port of Fred Hebert’s “Zippers” library, under the MIT licence.

Summary

Types

t()

A Zipper forest

Functions

Delete the node at the current position. The next one on the right will take its place

Moves down the forest to the children of the current node. If we are already at the bottom, this function returns nil

Insert a new node at the current position

Moves to the next node from the current item. If there is no next node, this function returns nil

Moves to the previous node from the current item. If we are already at the top, this function returns nil

Replace the node at the current position with value

Create an empty zipper forest with value as its first element

Moves up the forest to the parent of the current node, while rewinding the current node’s child list. This allows the programmer to access children as it it were the first time, all the time. If we are already at the top, this function returns nil

Moves up the forest to the parent of the current node, without rewinding the current node’s child list. If we are already at the top, this function returns nil

Extract the node value from the current tree position as {:ok, value}. If there is no item, the function returns {:error, nil}

Types

t()
t() :: {thread, znode}

A Zipper forest

Functions

delete(arg)

Delete the node at the current position. The next one on the right will take its place.

down(arg)

Moves down the forest to the children of the current node. If we are already at the bottom, this function returns nil.

insert(arg, value)
insert(Zippy.ZForest.t, term) :: Zippy.ZForest

Insert a new node at the current position.

next(arg)
next(Zippy.ZForest.t) :: Zippy.ZForest | nil

Moves to the next node from the current item. If there is no next node, this function returns nil.

prev(arg)

Moves to the previous node from the current item. If we are already at the top, this function returns nil.

replace(arg, value)
replace(Zippy.ZForest.t, term) :: Zippy.ZForest

Replace the node at the current position with value.

root(value)
root(term) :: Zippy.ZForest.t

Create an empty zipper forest with value as its first element.

rup(arg)

Moves up the forest to the parent of the current node, while rewinding the current node’s child list. This allows the programmer to access children as it it were the first time, all the time. If we are already at the top, this function returns nil.

up(arg)

Moves up the forest to the parent of the current node, without rewinding the current node’s child list. If we are already at the top, this function returns nil.

value(arg)
value(Zippy.ZForest.t) :: {:ok, term} | {:error, nil}

Extract the node value from the current tree position as {:ok, value}. If there is no item, the function returns {:error, nil}