Module zipper

Generic Zipper Implementation.

Description

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

Data Types

children_fun()

children_fun(T) = fun((T) -> [T])

info()

info(T) = #{lefts => [T], rights => [T], parent_node => undefined | T, parent_info => undefined | info(T), is_modified => boolean()}

is_branch_fun()

is_branch_fun(T) = fun((T) -> boolean())

make_node_fun()

make_node_fun(T) = fun((T, [T]) -> T)

operation()

operation() = next | prev | up | down | left | right | root | node | rightmost | leftmost

zipper()

abstract datatype: zipper(T)

Function Index

append_child/2Adds a node as the rightmost child of the current one.
children/1Returns the list of children zippers.
down/1Returns the zipper in the first child, if any.
edit/3Edits the current node by applying the given function.
filter/2Returns a list of all the nodes in the zipper that match a predicate.
fmap/3Returns the root of the tree, where the value of each node (after the current location of Zipper) is replaced with the result from appling Fun to the node as the first argument and Args as additional arguments.
fold/3Applies Fun recursively on the zipper.
insert_child/2Adds a node as the leftmost child of the current one.
insert_left/2Inserts a node to the left of the current one.
insert_right/2Inserts a node to the right of the current one.
is_branch/1Is this node a branch?.
is_end/1Is it the end of the zipper traversal.
left/1Returns the zipper on the left, if any.
leftmost/1Returns the leftmost zipper in the current zipper.
map/2Applies a function to all nodes of the zipper.
new/4Builds a new zipper with nodes of type T.
next/1Returns the next zipper.
node/1Returns the value of the current node in the zipper.
prev/1Returns the previous zipper.
remove/1Removes current node from zipper.
replace/2Replaces the current node.
right/1Returns the zipper on the right, if any.
rightmost/1Returns the rightmost zipper in the current zipper.
root/1Returns the node on the root of the zipper.
size/1Returns the size of the zipper.
traverse/2Traverses the zipper following the given list of operations.
up/1Returns the zipper in the parent node, if possible.

Function Details

append_child/2

append_child(T, Zipper::zipper(T)) -> zipper(T)

Adds a node as the rightmost child of the current one.

children/1

children(Zipper::zipper(T)) -> [zipper(T)]

Returns the list of children zippers.

down/1

down(Zipper::zipper(T)) -> zipper(T) | undefined

Returns the zipper in the first child, if any.

edit/3

edit(Fun::fun((...) -> T), Args::[term()], Zipper::zipper(T)) -> zipper(T)

Edits the current node by applying the given function. The parameters of said function will be [Node | Args].

filter/2

filter(Pred::fun((T) -> boolean()), Zipper::zipper(T)) -> [T]

Returns a list of all the nodes in the zipper that match a predicate.

fmap/3

fmap(Fun::fun((...) -> T), Args::[term()], Zipper::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 appling Fun to the node as the first argument and Args as additional arguments.

fold/3

fold(Fun::fun((T, A) -> A), A, Zipper::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.

insert_child/2

insert_child(T, Zipper::zipper(T)) -> zipper(T)

Adds a node as the leftmost child of the current one.

insert_left/2

insert_left(T, Zipper::zipper(T)) -> zipper(T)

Inserts a node to the left of the current one.

insert_right/2

insert_right(T, Zipper::zipper(T)) -> zipper(T)

Inserts a node to the right of the current one.

is_branch/1

is_branch(X1::zipper(term())) -> boolean()

Is this node a branch?

is_end/1

is_end(Zipper::zipper(term())) -> boolean()

Is it the end of the zipper traversal.

left/1

left(Zipper::zipper(T)) -> zipper(T) | undefined

Returns the zipper on the left, if any.

leftmost/1

leftmost(Zipper::zipper(T)) -> zipper(T)

Returns the leftmost zipper in the current zipper.

map/2

map(Fun::fun((T) -> U), Zipper::zipper(T)) -> [U]

Applies a function to all nodes of the zipper. Returns a list with the results.

new/4

new(IsBranch::is_branch_fun(T), Children::children_fun(T), MakeNode::make_node_fun(T), T) -> zipper(T)

Builds a new zipper with nodes of type T.

next/1

next(Zipper::zipper(T)) -> zipper(T)

Returns the next zipper.

node/1

node(X1::zipper(T)) -> T

Returns the value of the current node in the zipper.

prev/1

prev(Zipper::zipper(T)) -> zipper(T) | undefined

Returns the previous zipper.

remove/1

remove(X1::zipper(T)) -> zipper(T)

Removes current node from zipper. Moves down, if possible. If not, it moves to the rightmost node.

replace/2

replace(T, Zipper::zipper(T)) -> zipper(T)

Replaces the current node.

right/1

right(Zipper::zipper(T)) -> zipper(T) | undefined

Returns the zipper on the right, if any.

rightmost/1

rightmost(Zipper::zipper(T)) -> zipper(T)

Returns the rightmost zipper in the current zipper.

root/1

root(Zipper::zipper(T)) -> T

Returns the node on the root of the zipper.

size/1

size(Zipper::zipper(term())) -> non_neg_integer()

Returns the size of the zipper.

traverse/2

traverse(Rest::[operation()], Zipper::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.

up/1

up(Zipper::zipper(T)) -> zipper(T) | undefined

Returns the zipper in the parent node, if possible.


Generated by EDoc, May 11 2016, 14:35:50.