peterszerzo/elm-arborist/2.2.1

NOTE: this package is not compatible with Elm 0.19.1

Arborist.Tree

A tiny tiny tree module. Only a few utility methods are provided here - after all, if you want to manupilate the tree, you should probably do so using the interface 🤓.

Type

type Tree node
= Empty
| Node node (List (Tree node))

Recursive tree structure, holding any data type node, and any number of child nodes. Creating a tree of strings, for instance, would look like this:

Tree.Node "Parent" [ Tree.Node "Child1" [], Tree.Node "Child2" [] ]

Json

decoder : Decoder node -> Decoder (Tree node)

Tree decoder as a function of the node's decoder. Assumes a value and children fields, holding the current node contents and an array of children, respectively.

encoder : (node -> Value) -> Tree node -> Value

Encodes a tree into JSON, given its node encoder.

Methods

depth : Tree node -> Int

Tree depth.

flatten : Tree a -> List ( List Int, a )

Flatten a tree into a list of ( path, node ) tuples. The path is a list of integers showing how you can get to the node (the root would be [], its first child [ 1 ]).

map : (a -> b) -> Tree a -> Tree b

Map over the nodes of the tree.