graphqexl v0.1.0-alpha-rc.25 Treex.Tree

Primarily a struct for representing tree data to be processed with the Tree.Traverse module. Also includes implementations necessary for the Enumerable protocol and conversion functions to/from ordinary Map.t/0 representations of the same data.

One import note is the notion of a "virtual root." In order to represent arbitrary maps, any map that has multiple top-level keys (i.e. has multiple roots and is a graph, not a tree) will be converted to a tree by inserting a root node whose value defaults to :root and can be specified as the second parameter to Treex.Tree.from_map/2.

Link to this section Summary

Functions

Counts the number of nodes in the given tree.

Convert the given map into a Treex.Tree.t/0. If the given map has more than one top-level key, the optional root parameter specifies what value to give a virtual root node that will be inserted at the top of the key and contain the given map's top-level keys as children.

Checks whether the given node is a leaf node or not.

List the leaf nodes of the given Treex.Tree.t/0

Checks whether the given element is a member of the tree at any depth, performed breadth-first.

Reduces the given tree into the given accumulator by invoking the given Treex.Tree.reducer/0 function on each node, traversed breadth-first. The return is tagged tuple following the Enumerable protocol.

Generates a function that contiguously slices the given tree. See Enumerable.slice/1

Convert the given tree to a Map.t/0. Optionally, remove the root node by passing pop_root: true as a keyword option. This is useful, for example, when the caller knows the given tree has a virtual root.

Link to this section Types

Link to this type

acc()

acc() :: {:cont, term()} | {:halt, term()} | {:suspend, term()}
Link to this type

continuation()

continuation() :: (acc() -> result())
Link to this type

element()

element() :: {term(), [term()] | Map.t() | term()}
Link to this type

length()

length() :: pos_integer()
Link to this type

reducer()

reducer() :: (term(), term() -> acc())
Link to this type

result()

result() ::
  {:done, term()} | {:halted, term()} | {:suspended, term(), continuation()}
Link to this type

slicing_fun()

slicing_fun() :: (start(), length() -> [term()])
Link to this type

t()

t() :: %Treex.Tree{children: [t()], key: term(), value: any()}

Link to this section Functions

Link to this function

count(tree)

(since 0.1.0)
count(t()) :: {:ok, size()} | {:error, module()}

Counts the number of nodes in the given tree.

Returns: t:integer

Link to this function

from_map(map, root \\ :root)

(since 0.1.0)
from_map(Map.t(), term()) :: t()

Convert the given map into a Treex.Tree.t/0. If the given map has more than one top-level key, the optional root parameter specifies what value to give a virtual root node that will be inserted at the top of the key and contain the given map's top-level keys as children.

Returns: Treex.Tree.t/0

Link to this function

leaf_node?(node)

(since 0.1.0)
leaf_node?(t()) :: boolean()

Checks whether the given node is a leaf node or not.

Returns: boolean/0

Link to this function

leaves(tree)

(since 0.1.0)
leaves(t()) :: [t()] | []

List the leaf nodes of the given Treex.Tree.t/0

Returns: [t:Treex.Tree.t/0]

Link to this function

member?(tree, element)

(since 0.1.0)
member?(t(), term()) :: {:ok, boolean()} | {:error, module()}

Checks whether the given element is a member of the tree at any depth, performed breadth-first.

Returns: t:boolean

Link to this function

reduce(tree, acc, fun)

(since 0.1.0)
reduce(t(), acc(), reducer()) :: result()

Reduces the given tree into the given accumulator by invoking the given Treex.Tree.reducer/0 function on each node, traversed breadth-first. The return is tagged tuple following the Enumerable protocol.

Returns: Treex.Tree.acc/0 (where term is the same type as the acc parameter)

Link to this function

slice(tree)

(since 0.1.0)
slice(t()) :: {:ok, size(), slicing_fun()} | {:error, module()}

Generates a function that contiguously slices the given tree. See Enumerable.slice/1

Returns {:ok, t:non_neg_integer/0, t:Treex.Tree.slicing_fun/0} when successful {:error, t:module/0} when there is an error

Link to this function

to_map(tree, opts \\ [pop_root: false])

(since 0.1.0)
to_map(t() | [t()], [{:pop_root, boolean()}]) :: Map.t()

Convert the given tree to a Map.t/0. Optionally, remove the root node by passing pop_root: true as a keyword option. This is useful, for example, when the caller knows the given tree has a virtual root.