From 05e1cc51b2fb0824580925b55319377305105c44 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Sun, 28 Jan 2024 23:40:30 +0100 Subject: feat(zipper): add option to not move past last element when moving right --- lib/zipper.mli | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'lib/zipper.mli') diff --git a/lib/zipper.mli b/lib/zipper.mli index a300b12..0481cfe 100644 --- a/lib/zipper.mli +++ b/lib/zipper.mli @@ -46,8 +46,10 @@ val focus_or : default:'a -> 'a zipper -> 'a val is_far_left : 'a zipper -> bool (** Return whether the cursor is at the beginning of the zipper. *) -val is_far_right : 'a zipper -> bool -(** Return whether the cursor is at the end of the zipper. *) +val is_far_right : ?by_one:bool -> 'a zipper -> bool +(** Return whether the cursor is at the end of the zipper. + If [by_one] is [true], the cursor is considered at the far right + even when pointing {b to} the last element of the sequence. *) val is_empty : 'a zipper -> bool (** Return whether the zipper is empty. *) @@ -79,26 +81,30 @@ val left_while : ('a -> bool) -> 'a zipper -> 'a zipper val far_left : 'a zipper -> 'a zipper (** Move the cursor to the left, as much as possible. *) -val right : 'a zipper -> 'a zipper -(** Move the cursor one step to the right, if possible. +val right : ?by_one:bool -> 'a zipper -> 'a zipper +(** Move the cursor one step to the right, if possible. If [by_one] is + [true], the cursor won't move past the last element. Calling [right z], - if [z] is [([3; 2; 1], [4; 5])], the result is [([4; 3; 2; 1], [5])], - if [z] is [([1; 2; 3], [])], the result is [([1; 2; 3], [])]. *) -val right_while : ('a -> bool) -> 'a zipper -> 'a zipper +val right_while : ?by_one:bool -> ('a -> bool) -> 'a zipper -> 'a zipper (** [right_while f z] moves the cursor in [z] to the right as long as the predicate [f] is [true] when applied to the focus, or the right - end of the zipper is reached. *) + end of the zipper is reached. If [by_one] is [true], the cursor won't + move past the last element. *) -val far_right : 'a zipper -> 'a zipper -(** Move the cursor to the right, as much as possible. *) +val far_right : ?by_one:bool -> 'a zipper -> 'a zipper +(** Move the cursor to the right, as much as possible. If [by_one] is + [true], the cursor won't move past the last element.*) -val goto : int -> 'a zipper -> 'a zipper +val goto : ?by_one:bool -> int -> 'a zipper -> 'a zipper (** Move the cursor to a specific (absolute) position in the zipper. Depending on the current position, it either moves the cursor - forward or backwards, without crossing the zipper boundaries. *) + forward or backwards, without crossing the zipper boundaries. If + [by_one] is [true], the cursor won't move past the last element. *) (** {1 Changes at the cursor} *) -- cgit v1.2.3