View Source CTE.Utils (Closure Table v1.1.2)

Basic utilities for helping developing functionality about the CTE data structures

Link to this section Summary

Functions

render a path hierarchy as a .dot string that you could use for drawing your results, using graphviz. w⦿‿⦿t!

print the tree at the console, using a custom function for selecting the info to be displayed

converts the given tree into a nested map

Link to this section Functions

Link to this function

tree_to_map(map, id, opts \\ [])

View Source

converts the given tree into a nested map

This function receives a tree structure returned by the CTE and the id of an existing node we want to start from. It returns a nested map representation of the tree.

options

Options

  • :callback - a function of arity one that accepts the current node as input and outputs a formatted node. Defaults to & &1.

Example:

iex» {:ok, tree} = CTT.tree(1) iex» CTE.Utils.tree_to_map(tree, 6, callback: &Map.take(&1, [:text]))

%{ 6 => %{

"children" => %{
  8 => %{
    "children" => %{},
    "node" => %{
      text: "I'm sold! And I'll use its Elixir implementation! <3"
    }
  },
  9 => %{"children" => %{}, "node" => %{text: "w⦿‿⦿t!"}}
},
"node" => %{text: "Everything is easier, than with the Nested Sets."}

} }