aboutsummaryrefslogtreecommitdiff
path: root/lib/zipper.ml
diff options
context:
space:
mode:
authorMarc Coquand <marc@mccd.space>2024-05-13 11:00:47 -0500
committerMarc Coquand <marc@mccd.space>2024-05-13 11:00:47 -0500
commit121a6a376209de3f5a9474bf03721e2032a73e01 (patch)
tree6f02ffa1695510aa9227a9290abac11811b25373 /lib/zipper.ml
downloadstitch-121a6a376209de3f5a9474bf03721e2032a73e01.tar.gz
stitch-121a6a376209de3f5a9474bf03721e2032a73e01.tar.bz2
stitch-121a6a376209de3f5a9474bf03721e2032a73e01.zip
initial commit
Diffstat (limited to 'lib/zipper.ml')
-rw-r--r--lib/zipper.ml22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/zipper.ml b/lib/zipper.ml
new file mode 100644
index 0000000..37e14de
--- /dev/null
+++ b/lib/zipper.ml
@@ -0,0 +1,22 @@
+type zipper =
+ { above : string list
+ ; selected : string
+ ; below : string list
+ }
+
+let up (zipper : zipper) =
+ match zipper.above with
+ | [] -> zipper
+ | a :: rest -> { above = rest; selected = a; below = zipper.selected :: zipper.below }
+
+
+let down (zipper : zipper) =
+ match zipper.below with
+ | [] -> zipper
+ | a :: rest -> { below = rest; selected = a; above = zipper.selected :: zipper.above }
+
+
+let selected zipper = zipper.selected
+
+let to_array zipper =
+ List.concat [ zipper.above; [ zipper.selected ]; zipper.below ] |> Array.of_list