Location in a Forest
( Basics.Int, Tree.Path.TreePath )
The unique location of a Tree
in a Forest
.
Describes which tree to step inside
plus the TreePath
to navigate inside that tree.
Represented as a tuple to simplify pattern matching and enable using it as a comparable
key.
Instead of working with that tuple directly, I recommend using the helpers here to create and operate on these paths.
fromIndex : Basics.Int -> Tree.Path.TreePath -> ForestPath
Construct a ForestPath
from the treeIndex
and pathIntoTreeAtIndex
import Tree
import Tree.Path
import Forest.Navigate
[ Tree.singleton 0
, Tree.singleton 1
]
|> Forest.Navigate.to (Forest.Path.fromIndex 1 Tree.Path.atTrunk)
--> Just (Tree.singleton 1)
treeIndex : ForestPath -> Basics.Int
Which tree to step inside in a Forest
pathIntoTreeAtIndex : ForestPath -> Tree.Path.TreePath
The TreePath
to navigate inside the tree at the treeIndex
.
toChild : Basics.Int -> ForestPath -> ForestPath
The path to its ...th child from there.
import Tree.Path
Forest.Path.fromIndex 1 Tree.Path.atTrunk
|> Forest.Path.toChild 4
|> Forest.Path.toChild 1
|> Forest.Path.toChild 8
--> Forest.Path.fromIndex 1 (Tree.Path.follow [ 4, 1, 8 ])
At the first tree: