diff options
-rw-r--r-- | lib/zipper.ml | 5 | ||||
-rw-r--r-- | lib/zipper.mli | 4 |
2 files changed, 9 insertions, 0 deletions
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 = | |||
107 | | None -> z | 107 | | None -> z |
108 | | Some (h, t) -> { z with after = Sequence.shift_right t (f h) } | 108 | | Some (h, t) -> { z with after = Sequence.shift_right t (f h) } |
109 | 109 | ||
110 | let map_focus_or ~default f z = | ||
111 | match Sequence.next z.after with | ||
112 | | None -> { z with after = Sequence.singleton default } | ||
113 | | Some (h, t) -> { z with after = Sequence.shift_right t (f h) } | ||
114 | |||
110 | let map f z = | 115 | let map f z = |
111 | { z with before = Sequence.map ~f z.before; after = Sequence.map ~f z.after } | 116 | { z with before = Sequence.map ~f z.before; after = Sequence.map ~f z.after } |
112 | 117 | ||
diff --git a/lib/zipper.mli b/lib/zipper.mli index beeb181..e25d57b 100644 --- a/lib/zipper.mli +++ b/lib/zipper.mli | |||
@@ -198,6 +198,10 @@ val map_after : ('a -> 'a) -> 'a zipper -> 'a zipper | |||
198 | val map_focus : ('a -> 'a) -> 'a zipper -> 'a zipper | 198 | val map_focus : ('a -> 'a) -> 'a zipper -> 'a zipper |
199 | (** Map a function over the element focused by the cursor, if any. *) | 199 | (** Map a function over the element focused by the cursor, if any. *) |
200 | 200 | ||
201 | val map_focus_or : default:'a -> ('a -> 'a) -> 'a zipper -> 'a zipper | ||
202 | (** Map a function over the element focused by the cursor. Push | ||
203 | [default] if no element is focused. *) | ||
204 | |||
201 | val map : ('a -> 'a) -> 'a zipper -> 'a zipper | 205 | val map : ('a -> 'a) -> 'a zipper -> 'a zipper |
202 | (** Map a function over all elements of a zipper. *) | 206 | (** Map a function over all elements of a zipper. *) |
203 | 207 | ||