コード例 #1
0
ファイル: Tree.java プロジェクト: jbgi/functionaljava
 /**
  * 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()));
 }
コード例 #2
0
ファイル: Tree.java プロジェクト: jbgi/functionaljava
 /**
  * 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))));
 }