View Source CTE.Utils (Closure Table v2.0.5)

Basic utilities for helping developing functionality about the CTE data structures

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

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

  • :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]))

%{ "children" => [

%{
  "children" => [],
  "id" => 8,
  "node" => %{text: "I’m sold! And I’ll use its Elixir implementation! <3"}
},
%{"children" => [], "id" => 9, "node" => %{text: "w⦿‿⦿t!"}}

], "id" => 6, "node" => %{text: "Everything is easier, than with the Nested Sets."} }