Redo tree composition

This commit is contained in:
2022-06-10 00:08:32 +01:00
parent 3edc7a0a58
commit 5532c25d3c
13 changed files with 114 additions and 52 deletions
+9
View File
@@ -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]