Working with hierarchical lists.
Flatten a tree into a list of labels.
Tree.map (\label -> String.trim label) tree
--> Tree "*"
--> [ Tree "A" [ Tree "p" [], Tree "q" [] ]
--> , Tree "B" []
--> ]
Tree.map (\label -> String.trim label) tree
|> toList
--> [ "*", "A", "p", "q", "B"]Given a function that maps labels to strings, construct a string that represents the tree as an outline.
> t |> toOutline identity
"*\nA\n p\n q\nB\n r\n s\nC" : StringThe string returned is
*
A
p
q
Bdepth t is the depth of the tree.
> depth t
2 : Intnodecount t is the number of notes in the tree t
> nodeCount t
8 : IntThe count includes the root.
The tagWithDepth function transforms a tree of items into
a tree of tuples of the form (a, k), where k is the
depth of a in the tree.
> tagWithDepth (Tree.map String.trim tree)
Tree ("*",0) [
Tree ("A",1) [Tree ("p",2) [],Tree ("q",2) []]
,Tree ("B",1) []
]
Given:
fromListreturns the corresponding rose tree. For an example, consider this snippet