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 node
  • rights/1 - returns the rights siblings of the focus node
  • path/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 node
  • down/1 - moves to the first child of the focus node
  • up/1 - moves to the parent of the focus node
  • left/1 - moves to the left sibling of the focus node
  • leftmost/1 - moves to the leftmost sibling of the focus node
  • right/1 - moves to the right sibling of the focus node
  • rightmost/1 - moves to the rightmost sibling of the focus node
  • next/1 - moves to the next node in a depth-first traversal
  • prev/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

Link to this type

edit_fun()

View Source
edit_fun() :: (element() -> element())
Link to this type

edit_with_args_fun()

View Source
edit_with_args_fun() :: (element(), args() -> element())
Link to this type

element()

View Source
element() :: any()
Link to this type

t()

View Source
t() :: %Zippex{
  ctx: Zippex.Context.t() | :end,
  node: element(),
  spec: Zippex.Meta.t()
}

Link to this section Functions

Link to this function

down(zipper)

View Source
down(t()) :: t() | nil

Moves to the first child of the focus node.

Returns the updated zipper, or nil if the focus node has no children.

Link to this function

edit(zipper, fun)

View Source
edit(t(), edit_fun()) :: t()

Modifies the focus node by applying a function to it.

Link to this function

edit(zipper, fun, args)

View Source
edit(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.

Link to this function

left(zipper)

View Source
left(t()) :: t() | nil

Moves to the left sibling of the focus node.

Returns the updated zipper, or nil if the focus node has no left sibling.

Link to this function

leftmost(zipper)

View Source
leftmost(t()) :: t()

Moves to the leftmost sibling of the focus node.

Returns the updated zipper.

Link to this function

lefts(zippex)

View Source
lefts(t()) :: [element()]

Returns the left siblings of the focus node.

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.

Link to this function

next(zipper)

View Source
next(t()) :: t()

Moves to the next node of the focus node in a depth-first traversal.

Returns the path to the focus node.

Link to this function

prev(zipper)

View Source
prev(t()) :: t()

Moves to the previous node of the focus node in a depth-first traversal.

Link to this function

remove(zipper)

View Source
remove(t()) :: t()

Removes the focus node, moving the focus to the node that would have preceded it in a depth-first traversal.

Link to this function

right(zipper)

View Source
right(t()) :: t() | nil

Moves to the right sibling of the focus node.

Returns the updated zipper, or nil if the focus node has no right sibling.

Link to this function

rightmost(zipper)

View Source
rightmost(t()) :: t()

Moves to the rightmost sibling of the focus node.

Returns the updated zipper.

Link to this function

rights(zippex)

View Source
rights(t()) :: [element()]

Returns the right siblings of the focus node.

Returns the root node of the zipper.

Link to this function

up(zipper)

View Source
up(t()) :: t() | nil

Moves to the parent of the focus node.

Returns the updated zipper, or nil if the focus node has no parent.