A key-value tree for Excel (accounting) data. The format is [Label [Children]] for nodes and [Label {:column :value}] for leaves.
For some example code, check out the various (comment ...) blocks in this namespace.
A key-value tree for Excel (accounting) data. The format is [Label [Children]] for nodes and [Label {:column :value}] for leaves. For some example code, check out the various (comment ...) blocks in this namespace.
(accounting-table trees
&
{:keys [aggregate-with min-leaf-depth]
:or {aggregate-with sum-maps min-leaf-depth 2}})
Render a coll of trees into a coll of tabular maps, where leaf values are listed on the same line and aggregated below into a total (default aggregation is addition).
Each item in the coll is a map with ::depth, ::label, ::header?, and ::total? attributes, in addition to the attributes in the leaves.
If an :aggregate-with
function is provided, total lines are constructed by
reducing that function over sub-leaves. Defaults to a reducing with sum-maps
.
Render a coll of trees into a coll of tabular maps, where leaf values are listed on the same line and aggregated below into a total (default aggregation is addition). Each item in the coll is a map with ::depth, ::label, ::header?, and ::total? attributes, in addition to the attributes in the leaves. If an `:aggregate-with` function is provided, total lines are constructed by reducing that function over sub-leaves. Defaults to a reducing with `sum-maps`.
(children node)
The node's children, or [] in the case of a leaf.
The node's children, or [] in the case of a leaf.
(headers tree first-hs last-hs)
Return a vector of headers in the tree, with any headers given in first-hs at the beginning and and in last-hs in order.
Return a vector of headers in the tree, with any headers given in first-hs at the beginning and and in last-hs in order.
(math form)
Any calls to + or - within form are modified to work on trees and tree values (maps of numbers).
Any calls to + or - within form are modified to work on trees and tree values (maps of numbers).
(merge-trees root-label & trees)
Merge the children of the provided trees under a single root.
Merge the children of the provided trees under a single root.
(negate-tree tree)
Negate all of the numbers in a tree.
Negate all of the numbers in a tree.
(ordered-group-by f xs)
Like group-by
, but returns a [k [v]] seq and doesn't rearrange values except
to include them in a group. Probably less performant because it has to search
the built up seq to find the proper key-value store.
Like `group-by`, but returns a [k [v]] seq and doesn't rearrange values except to include them in a group. Probably less performant because it has to search the built up seq to find the proper key-value store.
(print-table xs)
(print-table xs {:keys [ks empty-str pad-width]})
Display tabular data in a way that preserves label indentation in a way the clojure.pprint/print-table does not.
Display tabular data in a way that preserves label indentation in a way the clojure.pprint/print-table does not.
(render table-items & {:keys [indent-width] :or {indent-width 2}})
Given a coll of table items with a qualified ::depth and ::label keys, return a table items indenting labels with ::depth and keeping other keys as column labels, removing namespace qualified keywords.
(Used for printing in a string, rather than with Excel.)
Given a coll of table items with a qualified ::depth and ::label keys, return a table items indenting labels with ::depth and keeping other keys as column labels, removing namespace qualified keywords. (Used for printing in a string, rather than with Excel.)
(shallow tree)
'Shallow' the tree one level by getting rid of the root and combining its children. Doesn't modify a leaf.
'Shallow' the tree one level by getting rid of the root and combining its children. Doesn't modify a leaf.
(subtract-maps m1 m2)
(subtract-maps m1 m2 & ms)
Very important difference from (merge-with - ...):
(merge-with - {:foo 10} {:foo 5 :bar 5}) ; => {:foo 5, :bar 5}
(subtract-maps {:foo 10} {:foo 5 :bar 5}) ; => {:foo 5, :bar -5}
Very important difference from (merge-with - ...): (merge-with - {:foo 10} {:foo 5 :bar 5}) ; => {:foo 5, :bar 5} (subtract-maps {:foo 10} {:foo 5 :bar 5}) ; => {:foo 5, :bar -5}
(sum-maps m1 m2)
(sum-maps m1 m2 & ms)
Similar to (merge-with + ...) but treats nil keys as 0 values.
Similar to (merge-with + ...) but treats nil keys as 0 values.
(table->trees tabular format-leaf & node-fns)
Collapse a tabular collection of maps into a collection of trees, where the
label at each level of the tree is given by each of node-fns
and the columns
displayed are the result of format-leaf
, which returns a tabular map.
See the (comment ...) block under this method declaration for an example.
Collapse a tabular collection of maps into a collection of trees, where the label at each level of the tree is given by each of `node-fns` and the columns displayed are the result of `format-leaf`, which returns a tabular map. See the (comment ...) block under this method declaration for an example.
(unaggregated-table trees)
Similar to account-table, but makes no attempt to aggregate non-leaf headers, and accepts a coll of trees.
Similar to account-table, but makes no attempt to aggregate non-leaf headers, and accepts a coll of trees.
(value tree)
(value tree reducing-fn)
Aggregate all of the leaf maps in tree
by reducing over them with
reducing-fn
(defaults to summing maps together). If given a single
map, returns the map.
Aggregate all of the leaf maps in `tree` by reducing over them with `reducing-fn` (defaults to summing maps together). If given a single map, returns the map.
(walk f tree)
(walk f branch? children root)
Map f across all [label attrs] and [label [child]] nodes, depth-first.
Use with the same branch?
and children
functions that you'd give to
tree-seq
in order to build a tree of the format used by this namespace.
Map f across all [label attrs] and [label [child]] nodes, depth-first. Use with the same `branch?` and `children` functions that you'd give to `tree-seq` in order to build a tree of the format used by this namespace.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close