Example #1
0
 /**
  * Folds this tree using the given monoid.
  *
  * @param f A transformation from this tree's elements, to the monoid.
  * @param m The monoid to fold this tree with.
  * @return The result of folding the tree with the given monoid.
  */
 public <B> B foldMap(final F<A, B> f, final Monoid<B> m) {
   return m.sum(f.f(root()), m.sumRight(subForest()._1().map(foldMap_(f, m)).toList()));
 }
Example #2
0
 /**
  * Maps the given function over this tree.
  *
  * @param f The function to map over this tree.
  * @return The new Tree after the function has been applied to each element in this Tree.
  */
 public <B> Tree<B> fmap(final F<A, B> f) {
   return node(
       f.f(root()), subForest().map(Stream.<Tree<A>, Tree<B>>map_().f(Tree.<A, B>fmap_().f(f))));
 }