summaryrefslogtreecommitdiffstats
path: root/TreeZipperUtils.hs
diff options
context:
space:
mode:
authorKierán Meinhardt <kieran.meinhardt@gmail.com>2020-09-23 17:44:40 +0200
committerKierán Meinhardt <kieran.meinhardt@gmail.com>2020-09-23 17:44:40 +0200
commit8e92e6e11d2b3b0bfb5ac9d68f347219493e6380 (patch)
tree6484ca42d85ca89475e922f7b45039c116ebbf97 /TreeZipperUtils.hs
parent6a6ad3aecd53ffd89101a0dee2b4ea576d4964d4 (diff)
split into library + executables
Diffstat (limited to 'TreeZipperUtils.hs')
-rw-r--r--TreeZipperUtils.hs52
1 files changed, 0 insertions, 52 deletions
diff --git a/TreeZipperUtils.hs b/TreeZipperUtils.hs
deleted file mode 100644
index 0c6dc00..0000000
--- a/TreeZipperUtils.hs
+++ /dev/null
@@ -1,52 +0,0 @@
-module TreeZipperUtils where
-
-import Data.Maybe
-import Data.Tree
-import Data.Tree.Zipper
-
--- Return loc (as parent-like structure) and parents.
-path :: TreePos Full a -> [(Forest a, a, Forest a)]
-path loc = toParent loc : parents loc
-
--- Return parent stack compatible form of loc.
-toParent :: TreePos Full a -> (Forest a, a, Forest a)
-toParent loc = (before loc, label loc, after loc)
-
-
-modifyFirstParentLabelWhere
- :: (a -> Bool)
- -> (a -> a)
- -> TreePos Full a
- -> TreePos Full a
-modifyFirstParentLabelWhere p f loc0 =
- case parent loc0 of
- Nothing -> loc0
- Just loc0' -> go (byChildIndex loc0) loc0'
- where
-
- go rewind loc =
- if p (label loc)
- then
- rewind (modifyLabel f loc)
- else
- case parent loc of
- Nothing -> rewind loc
- Just loc' ->
- go (rewind . byChildIndex loc) loc'
-
- -- generator for a rewind step
- byChildIndex :: TreePos Full a -> (TreePos Full a -> TreePos Full a)
- byChildIndex loc =
- -- The use of fromJust is safe here because we're only modifying
- -- labels and not the tree structure and thus the index is valid.
- fromJust . childAt (childIndex loc)
-
-
--- XXX This could be named more general, like countPrevSiblings?
--- XXX Can we kill the recursion?
-childIndex :: TreePos Full a -> Int
-childIndex =
- go 0
- where
- go index =
- maybe index (go $ index + 1) . prev