MackeyRMS / elm-rosetree-path / Forest.Path

Location in a Forest


type alias ForestPath =
( 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.

create

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)

observe

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.

alter

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:

  1. Take the branch at index 4
  2. Then take its branch at index 1
  3. Its child at index 8 is where the navigation should end