Additional helpers for a list of zwilias/elm-rosetrees
using ForestPath
Following the ForestPath, where do we end?
import Tree exposing (tree)
import Forest.Navigate
import Tree.Path
import Forest.Path
[ Tree.singleton "gee"
, tree "jo"
[ Tree.singleton "ann"
, tree "mic"
[ Tree.singleton "igg"
, Tree.singleton "dee"
, Tree.singleton "bee"
]
]
]
|> Forest.Navigate.to (Forest.Path.fromIndex 1 (Tree.Path.follow [ 1, 2 ]))
--> Just (Tree.singleton "bee")
[ Tree.singleton "gee"
, tree "jo"
[ Tree.singleton "ann"
, tree "mic"
[ Tree.singleton "igg"
, Tree.singleton "dee"
]
]
]
|> Forest.Navigate.to (Forest.Path.fromIndex 1 (Tree.Path.follow [ 1, 2 ]))
--> NothingChange its sub-tree at a given ForestPath based on its current value.
import Tree exposing (tree)
import Forest.Navigate
import Tree.Path
import Forest.Path
[ Tree.singleton "gee"
, tree "jo"
[ Tree.singleton "ann"
, tree "mic"
[ Tree.singleton "igg"
, Tree.singleton "dee"
, Tree.singleton "bee"
]
]
]
|> Forest.Navigate.alter (Forest.Path.fromIndex 1 (Tree.Path.follow [ 1, 2 ]))
(Tree.mapLabel String.toUpper)
--> [ Tree.singleton "gee"
--> , tree "jo"
--> [ Tree.singleton "ann"
--> , tree "mic"
--> [ Tree.singleton "igg"
--> , Tree.singleton "dee"
--> , Tree.singleton "BEE"
--> ]
--> ]
--> ]
[ Tree.singleton "gee"
, tree "jo"
[ Tree.singleton "ann"
, tree "mic"
[ Tree.singleton "igg"
, Tree.singleton "dee"
]
]
]
|> Forest.Navigate.alter (Forest.Path.fromIndex 1 (Tree.Path.follow [ 1, 2 ]))
(Tree.mapLabel String.toUpper)
--> [ Tree.singleton "gee"
--> , tree "jo"
--> [ Tree.singleton "ann"
--> , tree "mic"
--> [ Tree.singleton "igg"
--> , Tree.singleton "dee"
--> ]
--> ]
--> ]Remove the sub-Tree at the end of a given ForestPath
and its children.
import Tree exposing (tree)
import Forest.Navigate
import Tree.Path
import Forest.Path
[ Tree.singleton "ann"
, tree "mic"
[ Tree.singleton "igg"
, Tree.singleton "dee"
, Tree.singleton "bee"
]
]
|> Forest.Navigate.remove (Forest.Path.fromIndex 1 (Tree.Path.follow [ 2 ]))
--> [ Tree.singleton "ann"
--> , tree "mic"
--> [ Tree.singleton "igg"
--> , Tree.singleton "dee"
--> ]
--> ]
[ Tree.singleton "ann"
, tree "mic"
[ Tree.singleton "igg"
, Tree.singleton "dee"
]
]
|> Forest.Navigate.remove (Forest.Path.fromIndex 1 (Tree.Path.follow [ 2 ]))
--> [ Tree.singleton "ann"
--> , tree "mic"
--> [ Tree.singleton "igg"
--> , Tree.singleton "dee"
--> ]
--> ]Change every tree label based on its ForestPath and current value.
import Tree exposing (tree)
import Forest.Navigate
import Forest.Path
import Tree.Path
[ Tree.singleton -1
, tree 1
[ Tree.singleton 2
, tree 3 [ Tree.singleton 4 ]
, Tree.singleton 5
]
]
|> Forest.Navigate.map
(\n -> ( n.label * 2, n.path ))
--> [ Tree.singleton ( -2, Forest.Path.fromIndex 0 Tree.Path.atTrunk )
--> , tree ( 2, Forest.Path.fromIndex 1 Tree.Path.atTrunk )
--> [ Tree.singleton ( 4, Forest.Path.fromIndex 1 (Tree.Path.follow [ 0 ]) )
--> , tree ( 6, Forest.Path.fromIndex 1 (Tree.Path.follow [ 1 ]) )
--> [ Tree.singleton ( 8, Forest.Path.fromIndex 1 (Tree.Path.follow [ 1, 0 ]) ) ]
--> , Tree.singleton ( 10, Forest.Path.fromIndex 1 (Tree.Path.follow [ 2 ]) )
--> ]
--> ]
A
Listof zwilias/elm-rosetreesExample use cases