List.Accessors
This accessor combinator lets you access the label of a given Tree.
import Accessors exposing (..)
import Tree exposing (Tree, tree)
import Tree.Accessors as Tree
import Lens as L
leaf : a -> Tree a
leaf a =
tree a []
simpleTree : Tree String
simpleTree =
tree "root"
[ tree "a" [ leaf "b"]
, tree "x" [ leaf "y"]
]
get (Tree.label_) simpleTree
--> "root"
set (Tree.label_) "top 'o the mornin' to yah!" simpleTree
--> tree "top 'o the mornin' to yah!" [ tree "a" [ leaf "b" ] , tree "x" [ leaf "y" ] ]
map (Tree.label_) String.toUpper simpleTree
--> tree "ROOT" [ tree "a" [ leaf "b" ] , tree "x" [ leaf "y" ] ]This accessor combinator lets you access a sub-tree at a given TreePath.
import Accessors exposing (..)
import Tree exposing (Tree, tree)
import Tree.Accessors as Tree
import Lens as L
leaf : a -> Tree a
leaf a =
tree a []
simpleTree : Tree String
simpleTree =
tree "root"
[ tree "a" [ leaf "b"]
, tree "x" [ leaf "y"]
]
try (Tree.path [0,0]) simpleTree
--> Just (leaf "b")
set (Tree.path [1,0]) (tree "hey!" [leaf "deeper"]) simpleTree
--> tree "root" [ tree "a" [ leaf "b" ] , tree "x" [ tree "hey!" [leaf "deeper"] ] ]
map (Tree.path [0]) (Tree.updateLabel (\s -> "gimme an " ++ String.toUpper s ++ "!")) simpleTree
--> tree "root" [ tree "gimme an A!" [ leaf "b" ] , tree "x" [ leaf "y" ] ]This accessor combinator lets you modify the type of each label of a Tree.
import Accessors exposing (..)
import Tree exposing (Tree, tree)
import Tree.Accessors as Tree
import Lens as L
leaf : a -> Tree a
leaf a =
tree a []
simpleTree : Tree String
simpleTree =
tree "r"
[ tree "a" [ leaf "b"]
, tree "x" [ leaf "y"]
]
all Tree.each simpleTree
--> ["r", "a", "b", "x", "y"]
set Tree.each "1" simpleTree
--> tree "1" [ tree "1" [ leaf "1" ] , tree "1" [ leaf "1" ] ]
map Tree.each (\s -> "gimme an " ++ String.toUpper s ++ "!") simpleTree
--> tree "gimme an R!" [ tree "gimme an A!" [ leaf "gimme an B!" ] , tree "gimme an X!" [ leaf "gimme an Y!" ] ]
This accessor combinator lets you access the label at a particular TreePath.