Zippex v1.0.0 Zippex View Source
A Zipper is a representation of an aggregate data structure which allows it to be traversed and updated arbitrarily. This module implements tree-like semantics for traversing a data structure.
Focus
The current node of the zipper, also known as the focus node, can be
retrieved by calling the focus/1
function. The following functions
provide other information relating to the focus node:
lefts/1
- returns the left siblings of the focus noderights/1
- returns the rights siblings of the focus nodepath/1
- returns the path to the focus node from the root
Traversal
The focus can be moved using the following functions:
head/1
- moves to the root nodedown/1
- moves to the first child of the focus nodeup/1
- moves to the parent of the focus nodeleft/1
- moves to the left sibling of the focus nodeleftmost/1
- moves to the leftmost sibling of the focus noderight/1
- moves to the right sibling of the focus noderightmost/1
- moves to the rightmost sibling of the focus nodenext/1
- moves to the next node in a depth-first traversalprev/1
- moves to the previous node in a depth-first traversal
Enumeration
Zippex
implements the Enumerable
protocol, which allows it's values
to be enumerated in a depth-first traversal.
Updates
The focus node can be modified using the functions edit/2
or edit/3
.
It can be removed, along with it's children, using the remove/1
function,
after which the focus is moved to the previous node in a depth-first
traversal.
Link to this section Summary
Functions
Moves to the first child of the focus node.
Modifies the focus node by applying a function to it.
Modifies the focus node by applying a function to it.
Returns the focus node of a zipper.
Moves to the head of the zipper.
Moves to the left sibling of the focus node.
Moves to the leftmost sibling of the focus node.
Returns the left siblings of the focus node.
Returns a new Zipper for a given node
element.
Moves to the next node of the focus node in a depth-first traversal.
Returns the path to the focus node.
Moves to the previous node of the focus node in a depth-first traversal.
Removes the focus node, moving the focus to the node that would have preceded it in a depth-first traversal.
Moves to the right sibling of the focus node.
Moves to the rightmost sibling of the focus node.
Returns the right siblings of the focus node.
Returns the root node of the zipper.
Moves to the parent of the focus node.
Link to this section Types
t()
View Sourcet() :: %Zippex{ ctx: Zippex.Context.t() | :end, node: element(), spec: Zippex.Meta.t() }
Link to this section Functions
Moves to the first child of the focus node.
Returns the updated zipper, or nil
if the focus node has no children.
Modifies the focus node by applying a function to it.
edit(zipper, fun, args)
View Sourceedit(t(), edit_with_args_fun(), args()) :: t()
Modifies the focus node by applying a function to it.
Returns the focus node of a zipper.
Moves to the head of the zipper.
Moves to the left sibling of the focus node.
Returns the updated zipper, or nil
if the focus node has no left sibling.
Moves to the leftmost sibling of the focus node.
Returns the updated zipper.
Returns the left siblings of the focus node.
new(is_branch, children, make_node, root)
View Sourcenew( Zippex.Meta.is_branch_fun(), Zippex.Meta.children_fun(), Zippex.Meta.make_node_fun(), element() ) :: t()
Returns a new Zipper for a given node
element.
is_branch_fun
receives a node and returns true
if it is a branch, or
false
otherwise.
children_fun
receives a node (which is a branch) and returns a list of
it's child nodes.
make_node_fun
receives a parent node and a list of child nodes and
returns a new node.
Moves to the next node of the focus node in a depth-first traversal.
Returns the path to the focus node.
Moves to the previous node of the focus node in a depth-first traversal.
Removes the focus node, moving the focus to the node that would have preceded it in a depth-first traversal.
Moves to the right sibling of the focus node.
Returns the updated zipper, or nil
if the focus node has no right sibling.
Moves to the rightmost sibling of the focus node.
Returns the updated zipper.
Returns the right siblings of the focus node.
Returns the root node of the zipper.
Moves to the parent of the focus node.
Returns the updated zipper, or nil
if the focus node has no parent.