Function adapton::catalog::collections::tree_fold_up
[−]
[src]
pub fn tree_fold_up<Lev: Level, Leaf, T: TreeElim<Lev, Leaf>, Res: Hash + Debug + Eq + Clone + 'static, NilF: 'static, LeafF: 'static, BinF: 'static, NameF: 'static>(
tree: T,
nil: Rc<NilF>,
leaf: Rc<LeafF>,
bin: Rc<BinF>,
name: Rc<NameF>
) -> Res where
NilF: Fn() -> Res,
LeafF: Fn(Leaf) -> Res,
BinF: Fn(Lev, Res, Res) -> Res,
NameF: Fn(Name, Lev, Res, Res) -> Res,
Fold over the structure of the tree, with results flowing up, from nil
and leaf
cases to the binary cases of bin
and name
.
This folding pattern is suitable for aggregating the leaf elements via an associative operation, such as a monoid (e.g., counting, addition, multiplication, maximum, minimum, etc.).
See monoid_of_tree
for a wrapper function that offers this usage.
This folding pattern is also suitable for producing copies of the tree's structure.