jxxcarlson/elm-tree-builder/3.1.0

NOTE: the latest version is 7.0.0

Tree.Build

Tools for building a tree from a string or a list of blocks. A tree is represented in text as an outline:

Example:


    > data = "1\n 2\n 3\n 4\n5\n 6\n 7"


    > fromString "?" identity data
      Tree "0" [
            Tree "1" [Tree "2" [],Tree "3" [], Tree "4" []]
          , Tree "5" [Tree "6" [],Tree "7" []]
          ]

The first argument of fromString is a label for a default node. The second argument, of type (String -> node), tells how to build a node from a string representation of that node. Here we use the representation of rose trees of elm/rose-tree.

fromString : node -> (String -> node) -> String -> Result Error (Tree node)
fromBlocks : node -> (String -> node) -> List Block -> Result Error (Tree node)
a
-> (String -> a)
-> (a -> String)
-> String
-> Result Error (List (Tree a))

Example:

> forestFromString "?" identity identity "1\n 2\n 3"
  Ok [Tree "1" [Tree "2" [],Tree "3" []]]


> forestFromString "?" identity identity "1\n 2\n 3\n4\n 5\n 6"
Ok [Tree "1" [Tree "2" [],Tree "3" []],Tree "4" [Tree "5" [],Tree "6" []]]
a
-> (String -> a)
-> (a -> String)
-> List Block
-> Result Error (List (Tree a))
type Error
= EmptyBlocks
| BlocksNotWellFormed