Trees are maps, leaves are maps of something->(not a map).
Use ordered maps (like array-map) to enforce order.
Trees are maps, leaves are maps of something->(not a map). Use ordered maps (like array-map) to enforce order.
(combined-footer)
(combined-footer combine-with)
To build a table where each branch node is followed by its children and then a blank-labeled total row at the same :tree/indent as the header with a value equal to its combined leaves.
To build a table where each branch node is followed by its children and then a blank-labeled total row at the same :tree/indent as the header with a value equal to its combined leaves.
(combined-header)
(combined-header combine-with)
To build a table where each branch node is a row with values equal to its combined leaves.
To build a table where each branch node is a row with values equal to its combined leaves.
(fold f tree)
(fold f nil-value tree)
Fold the tree
leaves together into one combined leaf calling
(f (get leaf-1 k nil-value) (get leaf-2 k nil-value))
.
E.g. (fold + tree)
would sum all of the {label number}
leaves in tree,
equivalent to (apply merge-with + all-leaves)
.
However, (fold - tree)
is not (apply merge-with - all-leaves)
. They
differ because merge-with
only uses its function in case of collision;
(merge-with - {:x 1} {:y 1})
is {:x 1, :y 1}
. The result with fold
would be {:x 1, :y -1}
.
Fold the `tree` leaves together into one combined leaf calling `(f (get leaf-1 k nil-value) (get leaf-2 k nil-value))`. E.g. `(fold + tree)` would sum all of the `{label number}` leaves in tree, equivalent to `(apply merge-with + all-leaves)`. However, `(fold - tree)` is not `(apply merge-with - all-leaves)`. They differ because `merge-with` only uses its function in case of collision; `(merge-with - {:x 1} {:y 1})` is `{:x 1, :y 1}`. The result with `fold` would be `{:x 1, :y -1}`.
(fold-kvs f tree)
Fold the tree
leaves together into one combined leaf calling
(f k (get leaf-1 k) (get leaf-2 k))
.
The function f
is called for the union of all keys for both leaves,
so one of the values may be nil
.
Fold the `tree` leaves together into one combined leaf calling `(f k (get leaf-1 k) (get leaf-2 k))`. The function `f` is called for the _union_ of all keys for both leaves, so one of the values may be `nil`.
(indent table-rows)
(indent table-rows n)
Increase the :tree/indent of each table row by n
(default 1).
Increase the :tree/indent of each table row by `n` (default 1).
(leaf? x)
A leaf is any map whose values are not maps.
A leaf is any map whose values are not maps.
(negate tree)
Invert the sign of every leaf number for a tree
with leaves of x->number.
Invert the sign of every leaf number for a `tree` with leaves of x->number.
(print-table rows)
(print-table ks rows)
Pretty print a tree with the same signature as clojure.pprint/print-table
,
indenting rows according to a :tree/indent attribute.
E.g. (print-table (table tree))
Pretty print a tree with the same signature as `clojure.pprint/print-table`, indenting rows according to a :tree/indent attribute. E.g. (print-table (table tree))
(table tree)
(table f tree)
(table f k tree)
Given (fn f [parent-key node depth] => row-map)
, convert tree
into a
table of [row]
.
If no f
is provided, the default implementation creates a pivot table with
no aggregation of groups and a :tree/indent in each row corresponding to the
depth of the node.
Pass (combined-header)
or (combined-footer)
as f
to aggregate sub-trees
according to custom logic (summing by default).
Given `(fn f [parent-key node depth] => row-map)`, convert `tree` into a table of `[row]`. If no `f` is provided, the default implementation creates a pivot table with no aggregation of groups and a :tree/indent in each row corresponding to the depth of the node. Pass `(combined-header)` or `(combined-footer)` as `f` to aggregate sub-trees according to custom logic (summing by default).
(tree branch? children root k v)
Build a tree from the same arguments you would use for tree-seq
, plus
k
and v
functions for node keys and leaf value maps, respectively.
Build a tree from the same arguments you would use for `tree-seq`, plus `k` and `v` functions for node keys and leaf value maps, respectively.
(with-table-header label table-rows)
Prepend a table header with the given label & indent the following rows.
Prepend a table header with the given label & indent the following rows.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close