$root.traverse(
descend: node -> parent -> lastResult -> { ... },
mapping: node -> parent -> lastResult -> { ... },
compose: result -> childResults -> node -> parent -> { ... }
)
The traversal takes place in the following order:
mapping to it. The result of the visit is used in step 4.descend to the current node.compose is applied to the results generated for the current node and all its child nodes. The result of compose returns the final result of traverse. If no function compose is specified, the result of traverse is the result generated by the mapping function for the root node.rootType: Any object.
The traversal of the graph starts with this object.
descend (mandatory)Type: Function with up to three arguments (node, parent, lastResult ).
The descent in the graph is specified by the function descend, which calculates the next nodes to be visited after the current node. The function descend accepts the current node and optionally the parent node as well as the last result of the visit (lastResult). The last result is the return of the mapping function if a node is found more than once (otherwise null). The argument lastResult can be used to stop the visit to prevent endless recursion when traversing a cyclic graph (or to shorten the visit when traversing a directed acyclic graph).
mapping (mandatory)Type: Function with up to three arguments (, nodeparent, lastResult).
The mapping generates the result of the visit to a node. If traverse is used in a transaction, an operation can be performed on a node here; if mapping is not specified, the result of the visit is the visited node itself.
compose (optional)Type: Function with up to four arguments (, resultchildResults, node, parent).
The function generates the final result of traverse after the mapping result of a node and its children is available. If compose is not specified, the result of the transformation operation is the result of the mapping function applied to the root node.
The parameters of compose are
result: The result generated by the mapping function for the current node.childResultsA list of the results generated for each visited child of the current node.nodeThe current node.parentThe parent node of the current node.