Class Tree<A>
java.lang.Object
fj.data.Tree<A>
- All Implemented Interfaces:
Iterable<A>
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <A,B> Tree <B> <B> Tree<B> Applies the given function to all subtrees of this tree, returning a tree of the results (comonad pattern).cojoin()Expands this tree into a tree of trees, with this tree as the root label, and subtrees as the labels of child nodes (comonad pattern).Draws a 2-dimensional representation of a tree.drawSubTrees(Show<A> s, Stream<Tree<A>> ts) booleanflatten()Puts the elements of the tree into a Stream, in pre-order.flatten_()flatten :: Tree a -> [a] flatten t = squish t []<B> Tree<B> Maps the given function over this tree.fmap_()Provides a transformation to lift any function so that it maps over Trees.<B> BFolds this tree using the given monoid.Provides a function that folds a tree with the given monoid.getRoot()inthashCode()booleanisLeaf()iterator()Returns an iterator for this tree.static <A> Tree<A> leaf(A root) Creates a nullary tree.intlength()levels()Provides a stream of the elements of the tree at each level, in level order.node()First-class constructor of trees.static <A> Tree<A> Creates a new n-ary given a root and a subforest of length n.static <A> Tree<A> Creates a new tree given a root and a (potentially infinite) subforest.static <A> Tree<A> Creates a new tree given a root and a (potentially infinite) subforest.root()Returns the root element of the tree.root_()Provides a transformation from a tree to its root.Provides a show instance that draws a 2-dimensional representation of a tree.Returns a stream of the tree's subtrees.Provides a transformation from a tree to its subforest.Projects an immutable collection of this tree.toString()unfoldTree(F<B, P2<A, P1<Stream<B>>>> f) Builds a tree from a seed value.<B,C> Tree <C> Zips this tree with another, using the given function.<B,C> Tree <C> Zips this tree with another, using the given function.Methods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
root
-
subForest
-
-
Constructor Details
-
Tree
-
-
Method Details
-
iterator
-
leaf
Creates a nullary tree.- Parameters:
root- The root element of the tree.- Returns:
- A nullary tree with the root element in it.
-
node
-
node
-
node
-
node
-
root
-
subForest
-
root_
-
subForest_
-
flatten
-
flatten_
-
levels
-
fmap
-
fmap_
-
foldMap
-
toCollection
Projects an immutable collection of this tree.- Returns:
- An immutable collection of this tree.
-
foldMap_
Provides a function that folds a tree with the given monoid.- Parameters:
f- A transformation from a tree's elements to the monoid.m- A monoid to fold the tree with.- Returns:
- A function that, given a tree, folds it with the given monoid.
-
unfoldTree
-
cobind
Applies the given function to all subtrees of this tree, returning a tree of the results (comonad pattern).- Parameters:
f- A function to bind across all the subtrees of this tree.- Returns:
- A new tree, with the results of applying the given function to each subtree of this tree. The result of applying the function to the entire tree is the root label, and the results of applying to the root's children are labels of the root's subforest, etc.
-
cojoin
-
drawSubTrees
-
shift
-
drawTree
-
equals
-
hashCode
-
toString
-
draw
-
show2D
-
zipWith
Zips this tree with another, using the given function. The resulting tree is the structural intersection of the two trees.- Parameters:
bs- A tree to zip this tree with.f- A function with which to zip together the two trees.- Returns:
- A new tree of the results of applying the given function over this tree and the given tree, position-wise.
-
zipWith
Zips this tree with another, using the given function. The resulting tree is the structural intersection of the two trees.- Parameters:
bs- A tree to zip this tree with.f- A function with which to zip together the two trees.- Returns:
- A new tree of the results of applying the given function over this tree and the given tree, position-wise.
-
bottomUp
- Parameters:
t- A tree to fold from the bottom to the top.f- A function transforming the current node and a stream of already transformed nodes (its children) into a new node- Returns:
- The folded tree
-
getRoot
-
isLeaf
public boolean isLeaf() -
length
public int length()
-