Module
Hylograph.Optics.Tree
- Package
- purescript-hylograph-optics
- Repository
- afcondon/purescript-hylograph-optics
Tree Optics
Lenses, traversals, and folds for rose trees. These optics work with the Cofree-based Tree from psd3-tree.
#_leaves Source
_leaves :: forall a. Traversal' (Tree a) aTraverse all leaf nodes (nodes with no children).
toListOf _leaves tree
-- => List of all leaf values
over _leaves (*2) tree
-- Double all leaf values
#_branches Source
_branches :: forall a. Traversal' (Tree a) aTraverse all branch nodes (nodes with children).
toListOf _branches tree
-- => List of all branch values
#_atDepth Source
_atDepth :: forall a. Int -> Traversal' (Tree a) aTraverse all nodes at a specific depth. Depth 0 is the root, depth 1 is immediate children, etc.
toListOf (_atDepth 2) tree
-- => List of all grandchild values
#_allNodes Source
_allNodes :: forall a. Traversal' (Tree a) (Tree a)Traverse ALL nodes in the tree (pre-order). Note: This traverses subtrees, not just values.
toListOf _allNodes tree
-- => Every subtree in the tree