View Source zipper (zipper v1.1.0)

Generic Zipper Implementation. Zippers let you traverse immutable data structures with ease and flexibility.

Summary

Functions

Adds a node as the rightmost child of the current one.
Returns the list of children zippers.
Returns the zipper in the first child, if any.
Edits the current node by applying the given function. The parameters of said function will be [Node | Args].
Returns a list of all the nodes in the zipper that match a predicate.
Returns the root of the tree, where the value of each node (after the current location of Zipper) is replaced with the result from applying Fun to the node as the first argument and Args as additional arguments.
Applies Fun recursively on the zipper. The arguments of Fun will be (Node, Acc) where Acc is the result of the previous call or the initial value provided.
Adds a node as the leftmost child of the current one.
Inserts a node to the left of the current one.
Inserts a node to the right of the current one.
Is this node a branch?
Is it the end of the zipper traversal.
Returns the zipper on the left, if any.
Returns the leftmost zipper in the current zipper.
Applies a function to all nodes of the zipper. Returns a list with the results.
Builds a new zipper with nodes of type T.
Returns the next zipper.
Returns the value of the current node in the zipper.
Returns the previous zipper.
Removes current node from zipper. Moves down, if possible. If not, it moves to the rightmost node.
Replaces the current node.
Returns the zipper on the right, if any.
Returns the rightmost zipper in the current zipper.
Returns the node on the root of the zipper.
Returns the size of the zipper.
Traverses the zipper following the given list of operations. If, at some point, an operation is invalid, it will crash.
Returns the zipper in the parent node, if possible.

Types

-type children_fun(T) :: fun((T) -> [T]).
-type info(T) ::
    #{lefts => [T],
      rights => [T],
      parent_node => undefined | T,
      parent_info => undefined | info(T),
      is_modified => boolean()}.
-type is_branch_fun(T) :: fun((T) -> boolean()).
-type make_node_fun(T) :: fun((T, [T]) -> T).
-type operation() :: next | prev | up | down | left | right | root | node | rightmost | leftmost.
-opaque zipper(T)

Functions

-spec append_child(T, zipper(T)) -> zipper(T).
Adds a node as the rightmost child of the current one.
-spec children(zipper(T)) -> [zipper(T)].
Returns the list of children zippers.
-spec down(zipper(T)) -> zipper(T) | undefined.
Returns the zipper in the first child, if any.
-spec edit(fun((...) -> T), [term()], zipper(T)) -> zipper(T).
Edits the current node by applying the given function. The parameters of said function will be [Node | Args].
-spec filter(fun((T) -> boolean()), zipper(T)) -> [T].
Returns a list of all the nodes in the zipper that match a predicate.
-spec fmap(fun((...) -> T), [term()], zipper(T)) -> T.
Returns the root of the tree, where the value of each node (after the current location of Zipper) is replaced with the result from applying Fun to the node as the first argument and Args as additional arguments.
-spec fold(fun((T, A) -> A), A, zipper(T)) -> A.
Applies Fun recursively on the zipper. The arguments of Fun will be (Node, Acc) where Acc is the result of the previous call or the initial value provided.
-spec insert_child(T, zipper(T)) -> zipper(T).
Adds a node as the leftmost child of the current one.
-spec insert_left(T, zipper(T)) -> zipper(T).
Inserts a node to the left of the current one.
-spec insert_right(T, zipper(T)) -> zipper(T).
Inserts a node to the right of the current one.
-spec is_branch(zipper(_)) -> boolean().
Is this node a branch?
-spec is_end(zipper(_)) -> boolean().
Is it the end of the zipper traversal.
-spec left(zipper(T)) -> zipper(T) | undefined.
Returns the zipper on the left, if any.
-spec leftmost(zipper(T)) -> zipper(T).
Returns the leftmost zipper in the current zipper.
-spec map(fun((T) -> U), zipper(T)) -> [U].
Applies a function to all nodes of the zipper. Returns a list with the results.
Link to this function

new(IsBranch, Children, MakeNode, T)

View Source
-spec new(is_branch_fun(T), children_fun(T), make_node_fun(T), T) -> zipper(T).
Builds a new zipper with nodes of type T.
-spec next(zipper(T)) -> zipper(T).
Returns the next zipper.
-spec node(zipper(T)) -> T.
Returns the value of the current node in the zipper.
-spec prev(zipper(T)) -> zipper(T) | undefined.
Returns the previous zipper.
-spec remove(zipper(T)) -> zipper(T).
Removes current node from zipper. Moves down, if possible. If not, it moves to the rightmost node.
-spec replace(T, zipper(T)) -> zipper(T).
Replaces the current node.
-spec right(zipper(T)) -> zipper(T) | undefined.
Returns the zipper on the right, if any.
-spec rightmost(zipper(T)) -> zipper(T).
Returns the rightmost zipper in the current zipper.
-spec root(zipper(T)) -> T.
Returns the node on the root of the zipper.
-spec size(zipper(_)) -> non_neg_integer().
Returns the size of the zipper.
-spec traverse([operation()], zipper(T)) -> zipper(T) | T | undefined.
Traverses the zipper following the given list of operations. If, at some point, an operation is invalid, it will crash.
-spec up(zipper(T)) -> zipper(T) | undefined.
Returns the zipper in the parent node, if possible.