Redo tree composition
This commit is contained in:
@@ -19,6 +19,7 @@ module TreeHelp
|
||||
, addToTrunk
|
||||
, inorderNumberTree
|
||||
, updateSingleNodes
|
||||
, updateAllNodes
|
||||
, updateRandNode
|
||||
, safeUpdateSingleNode
|
||||
, msafeUpdateSingleNode
|
||||
@@ -80,6 +81,14 @@ applyToSubforest is = applyToSubtree is . over branches
|
||||
-- | otherwise = Node x (applyToSubTrunkBy cond f t : ts)
|
||||
--applyToSubTrunkBy _ _ t = t
|
||||
|
||||
updateAllNodes :: (a -> Bool) -> (Tree a -> Tree a) -> Tree a -> Tree a
|
||||
updateAllNodes f update t@(Node x ts)
|
||||
| f x = update t
|
||||
| otherwise = updateChildren
|
||||
where
|
||||
updateChildren = Node x (map (updateAllNodes f update) ts)
|
||||
|
||||
|
||||
-- gives the list of all updates to a single node
|
||||
-- there must be a better way of doing something like this
|
||||
updateSingleNodes :: (a -> Bool) -> (Tree a -> Tree a) -> Tree a -> [Tree a]
|
||||
|
||||
Reference in New Issue
Block a user