From fd4fc4ce9ad45a25ca3e77a434306aa2476161bb Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Fri, 12 Jan 2024 14:12:57 +0100 Subject: feat(zipper): add function to map on cursor focus with default --- lib/zipper.ml | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/zipper.ml') diff --git a/lib/zipper.ml b/lib/zipper.ml index 30be8eb..9313518 100644 --- a/lib/zipper.ml +++ b/lib/zipper.ml @@ -107,6 +107,11 @@ let map_focus f z = | None -> z | Some (h, t) -> { z with after = Sequence.shift_right t (f h) } +let map_focus_or ~default f z = + match Sequence.next z.after with + | None -> { z with after = Sequence.singleton default } + | Some (h, t) -> { z with after = Sequence.shift_right t (f h) } + let map f z = { z with before = Sequence.map ~f z.before; after = Sequence.map ~f z.after } -- cgit v1.2.3