To import as Tree exposing (leaf).
Following the TreePath, where do we end?
leaf "jo"
|> Tree.at TreePath.atTrunk
--> Just (leaf "jo")
tree "jo"
[ leaf "ann"
, tree "mic"
[ leaf "igg"
, leaf "dee"
, leaf "bee"
]
]
|> Tree.at (TreePath.go [ 1, 2 ])
--> Just (leaf "bee")
tree "jo"
[ leaf "ann"
, tree "mic"
[ leaf "igg"
, leaf "dee"
]
]
|> Tree.at (TreePath.go [ 1, 2 ])
--> NothingChange the sub-tree at a TreePath based on its current value.
tree "jo"
[ leaf "ann"
, tree "mic"
[ leaf "igg"
, leaf "dee"
, leaf "bee"
]
]
|> Tree.updateAt (TreePath.go [ 1, 2 ])
(Tree.mapLabel String.toUpper)
--> tree "jo"
--> [ leaf "ann"
--> , tree "mic"
--> [ leaf "igg"
--> , leaf "dee"
--> , leaf "BEE"
--> ]
--> ]
tree "jo"
[ leaf "ann"
, tree "mic"
[ leaf "igg"
, leaf "dee"
]
]
|> Tree.updateAt (TreePath.go [ 1, 2 ])
(Tree.mapLabel String.toUpper)
--> tree "jo"
--> [ leaf "ann"
--> , tree "mic"
--> [ leaf "igg"
--> , leaf "dee"
--> ]
--> ]Remove the sub-Tree at the end of a TreePath from a Tree.
[ leaf "ann"
, tree "mic"
[ leaf "igg"
, leaf "dee"
, leaf "bee"
]
]
|> Tree.removeAt (TreePath.go [ 1, 2 ])
--> [ leaf "ann"
--> , tree "mic"
--> [ leaf "igg"
--> , leaf "dee"
--> ]
--> ]
[ leaf "ann"
, tree "mic"
[ leaf "igg"
, leaf "dee"
]
]
|> Tree.removeAt (TreePath.go [ 1, 2 ])
--> [ leaf "ann"
--> , tree "mic"
--> [ leaf "igg"
--> , leaf "dee"
--> ]
--> ]
[ leaf "jo" ]
|> Tree.removeAt TreePath.atTrunk
--> []Replace the sub-tree at a TreePath with a new Tree.
tree "jo"
[ leaf "ann"
, tree "mic"
[ leaf "igg"
, leaf "dee"
, leaf "bee"
]
]
|> Tree.replaceAt (TreePath.go [ 1, 2 ])
(leaf "be")
--> tree "jo"
--> [ leaf "ann"
--> , tree "mic"
--> [ leaf "igg"
--> , leaf "dee"
--> , leaf "be"
--> ]
--> ]
tree "jo"
[ leaf "ann"
, tree "mic"
[ leaf "igg"
, leaf "dee"
]
]
|> Tree.replaceAt (TreePath.go [ 1, 2 ])
(leaf "be")
--> tree "jo"
--> [ leaf "ann"
--> , tree "mic"
--> [ leaf "igg"
--> , leaf "dee"
--> ]
--> ]Put a list of children after all current children.
tree "hello" [ leaf "you" ]
|> Tree.appendChildren
[ leaf "and", leaf "you" ]
--> tree "hello"
--> [ leaf "you", leaf "and", leaf "you" ]Put a list of children left to all current children.
tree "dear" [ leaf "George" ]
|> Tree.prependChildren
[ leaf "May", leaf "and" ]
--> tree "dear"
--> [ leaf "May", leaf "and", leaf "George" ]Take all the branches where condition is met. When a branch fails, all its children are checked.
tree { name = "boss tree", selected = Unselected }
[ tree { name = "hugg", selected = Selected }
[ leaf { name = "zugg", selected = Selected }
, leaf { name = "gugg", selected = Unselected }
]
, leaf { name = "naomi", selected = Unselected }
, tree { name = "unselmo", selected = Unselected }
[ leaf { name = "selmo", selected = Selected }
, leaf { name = "helmo", selected = Unselected }
]
]
|> Tree.children
|> Tree.when
(Tree.label
>> .selected
>> (==) Selected
)
--> [ tree { name = "hugg", selected = Selected }
--> [ leaf { name = "zugg", selected = Selected }
--> , leaf { name = "gugg", selected = Unselected }
--> ]
--> , leaf { name = "selmo", selected = Selected }
--> ]Alter every label based on its TreePath and current value.
tree 1
[ leaf 2
, tree 3 [ leaf 4 ]
, leaf 5
]
|> Tree.mapWithPath (\path n -> ( n * 2, path ))
--> tree ( 2, TreePath.atTrunk )
--> [ leaf ( 4, TreePath.go [ 0 ] )
--> , tree ( 6, TreePath.go [ 1 ] )
--> [ leaf ( 8, TreePath.go [ 1, 0 ] ) ]
--> , leaf ( 10, TreePath.go [ 2 ] )
--> ]
Alias to
Tree.singleton: ATreewithout children. It can be exposed → less noise.