Convert hierarchical lists to a rose tree, convert a rose tree to a list of node labels, convert a rose tree to a string representing the corresponding outline, etc. See HTreeExample.elm.
Map a tree to a list of node contents:
> import Tree
> t |> Tree.map (\label -> String.trim label)
Tree "*" [
Tree "A" [Tree "p" [],Tree "q" []]
,Tree "B" [Tree "r" [],Tree "s" []]
,Tree "C" []]
> t |> Tree.map (\label -> String.trim label) |> toList
["*","A","p","q","B","r","s","C"]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
B
r
s
CThe tag 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.
> tag (Tree.map String.trim t)
Tree ("*",0) [
Tree ("A",1) [Tree ("p",2) [],Tree ("q",2) []]
,Tree ("B",1) [Tree ("r",2) [],Tree ("s",2) []]
,Tree ("C",1) []]depth t is the depth of the tree.
> depth t
2 : Inodecount t is the number of notes in the tree t
> nodeCount t
8 : IntThe count includes the root.
Suppose give an list of items of type
a, a "root" element of typea, and a function that determines the level of an item. The functionfromListreturns the corresponding rose tree. For an example, consider the outline given by the string `Example.Test.o3:Then we have
The function
HS.levelreturns the number of leading spaces divided by 2 -- integer division, no remainder.