Tweaks
This commit is contained in:
+8
-6
@@ -27,6 +27,7 @@ module TreeHelp (
|
||||
safeUpdateSingleNode,
|
||||
numTraversable,
|
||||
treeAttachDeep,
|
||||
subtree,
|
||||
) where
|
||||
|
||||
import Control.Lens
|
||||
@@ -49,12 +50,7 @@ treePost xs = treeFromPost (init xs) (last xs)
|
||||
{- | Creates a tree with one trunk branch,
|
||||
input as a list, that ends in another tree.
|
||||
-}
|
||||
treeFromTrunk ::
|
||||
-- | The trunk
|
||||
[a] ->
|
||||
-- | The end of the tree
|
||||
Tree a ->
|
||||
Tree a
|
||||
treeFromTrunk :: [a] -> Tree a -> Tree a
|
||||
treeFromTrunk = flip $ foldr f
|
||||
where
|
||||
f x t = Node x [t]
|
||||
@@ -72,6 +68,12 @@ applyToSubtree :: [Int] -> (Tree a -> Tree a) -> Tree a -> Tree a
|
||||
applyToSubtree [] f t = f t
|
||||
applyToSubtree (i : is) f (Node x xs) = Node x (xs & ix i %~ applyToSubtree is f)
|
||||
|
||||
-- the following is probably better, but hasn't been checked
|
||||
subtree :: (Applicative g,Foldable f) => f Int -> (Tree b -> g (Tree b)) -> Tree b -> g (Tree b)
|
||||
subtree = foldr f id
|
||||
where
|
||||
f i g = (branches . ix i) . g
|
||||
|
||||
{- | Applies a function to a specific subforest determined by a list of indices.
|
||||
Partial.
|
||||
-}
|
||||
|
||||
Reference in New Issue
Block a user