package scalaz.example
import scalaz._
import collection.immutable.Stream
object ExampleTree {
def main(args: Array[String]) = run
import Scalaz._
def run {
val tree: Tree[Int] =
1.node(
2.leaf,
3.node(
4.leaf))
1.η[Tree] assert_=== 1.leaf
tree ∘ (1 +) assert_=== 2.node(3.leaf, 4.node(5.leaf))
val t2 = tree ∗ (x => (x == 2) ? x.leaf | x.node((-x).leaf))
t2 assert_=== 1.node((-1).leaf, 2.leaf, 3.node((-3).leaf, 4.node((-4).leaf)))
tree.collapse assert_=== 10
tree.foldMap(_.toString) assert_=== "1234"
val allTreeLocs: Tree[TreeLoc[Int]] = tree.loc.cojoin.toTree
allTreeLocs.map(_.getLabel) assert_=== tree
allTreeLocs.map(_.path).drawTree.println
leafPaths(tree).toList.map(_.toList.reverse) assert_=== List(List(1, 2), List(1, 3, 4))
}
def leafPaths[T](tree: Tree[T]): Stream[Stream[T]]
= tree.loc.cojoin.toTree.flatten.filter(_.isLeaf).map(_.path)
}