jxxcarlson/htree/1.0.0

NOTE: the latest version is 2.0.1

HTree.String

HTree.String has some convenience functions for dealing with outlines and trees whose nodes are labeled by strings.

parse : String -> Tree String
> import HTree.String exposing(..)
> import Example.Test exposing(..)


o3 = -- from Example.Test
A
  p
    1
    2
    3
  q
B
  r
  s
C


> t = parse o3
  Tree "*" [
     Tree "A" [Tree "p" [Tree "1" [],Tree "2" [],Tree "3" []],Tree "q" []]
    ,Tree "B" [Tree "r" [],Tree "s" []]
    ,Tree "C" []]


> t = parse o3 |> HTree.tag
  Tree ("*",0) [
     Tree ("A",1) [Tree ("p",2) [Tree ("1",3) [],Tree ("2",3) [],Tree ("3",3) []]],Tree ("q",1) []
    ,Tree ("B",1) [Tree ("r",2) [],Tree ("s",2) []]
    ,Tree ("C",1) []]
toString : Tree String -> String

Compute the string representation of a tree labeled by strings

> toString t
"*\nA\n  p\n    1\n    2\n    3\n  q\nB\n  r\n  s\nC" : String
toOutline : Tree String -> String

Compute the string representation of a tree labeled by strings; omit the root label

> toOutline t
"A\n  p\n    1\n    2\n    3\n  q\nB\n  r\n  s\nC" : String
level : String -> Int

Compute the level of a string: the number of leading spaces, divided by 2