Location in a Forest
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)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:
Take the branch at index 4
Then take its branch at index 1
Its child at index 8 is where the navigation should end
The unique location of a
Treein aForest.Describes which tree to step inside plus the
TreePathto navigate inside that tree.Represented as a tuple to simplify pattern matching and enable using it as a
comparablekey.Instead of working with that
Listdirectly, I recommend using the helpers here to create and operate on these paths.