A library for constructing multi-way trees. Each Tree carries two pieces of information, it's datum and children.
A list of Trees. Convenient for describing children.
Access the datum of the current tree
Access the children of the current tree
Reduce a Tree from the left.
Reduce a Tree from the right.
Flattens a Tree into a List where the root is the first element of that list.
A special version of flatten which flattens a Tree into a List of Tuples like (element, [all elements in subtree])
(Tree.tuplesOfDatumAndFlatChildren
Tree "a"
[ Tree "b" []
, Tree "c" []
, Tree "d" []
])
== [ ( "a", [ "b", "c", "d" ] ), ( "b", [] ), ( "c", [] ), ( "d", [] ) ]Filter the MultiwayTree. Keep only elements whose datum satisfy the predicate.
Filter the MultiwayTree. If the predicate is True for a Child the entire path to the root will be part of the result Tree.
Return the length of the Tree. Calculated recusively as datum (1) + length of children (n) Since a MultiwayTree is never empty this function will never return Int < 1.
Inserts a Tree as the first child of a Tree
Inserts a Tree as the last child of a Tree
Map over the MultiwayTree
Map a Function over a List and a MultiwayTree.
Same as map but the function is also applied to the index of each element (starting at zero).
Sort values by a derived property. Does not alter the nesting structure of the Tree, that is it does not move Nodes up or down levels.
(sortBy identity
Tree "a"
[ Tree "b" []
, Tree "d" []
, Tree "c" []
])
== (Tree "a"
[ Tree "b" []
, Tree "c" []
, Tree "d" []
])Sort values with a custom comparison function like:
flippedComparison a b =
case compare a b of
LT -> GT
EQ -> EQ
GT -> LT
This is also the most general sort function, allowing you
to define any other.
A type to keep track of datum and children.