diff --git a/src/core/CCList.ml b/src/core/CCList.ml index 5833d17d..f6239ecd 100644 --- a/src/core/CCList.ml +++ b/src/core/CCList.ml @@ -833,10 +833,18 @@ module Zipper = struct | x::l, r -> l, x::r | [], r -> [], r + let left_exn = function + | x::l, r -> l, x::r + | [], _ -> invalid_arg "zipper.left_exn" + let right = function | l, x::r -> x::l, r | l, [] -> l, [] + let right_exn = function + | l, x::r -> x::l, r + | _, [] -> invalid_arg "zipper.right_exn" + let modify f z = match z with | l, [] -> begin match f None with @@ -874,7 +882,11 @@ module Zipper = struct let drop_before (_, r) = [], r - let drop_after (l, _) = l, [] + let drop_after (l, r) = match r with + | [] -> l, [] + | x :: _ -> l, [x] + + let drop_after_and_focused (l, _) = l, [] end (** {2 References on Lists} *) diff --git a/src/core/CCList.mli b/src/core/CCList.mli index f470396e..c825a00c 100644 --- a/src/core/CCList.mli +++ b/src/core/CCList.mli @@ -331,9 +331,19 @@ module Zipper : sig val left : 'a t -> 'a t (** Go to the left, or do nothing if the zipper is already at leftmost pos *) + val left_exn : 'a t -> 'a t + (** Go to the left, or + @raise Invalid_argument if the zipper is already at leftmost pos + @since NEXT_RELEASE *) + val right : 'a t -> 'a t (** Go to the right, or do nothing if the zipper is already at rightmost pos *) + val right_exn : 'a t -> 'a t + (** Go to the right, or + @raise Invalid_argument if the zipper is already at rightmost position + @since NEXT_RELEASE *) + val modify : ('a option -> 'a option) -> 'a t -> 'a t (** Modify the current element, if any, by returning a new element, or returning [None] if the element is to be deleted *) @@ -365,8 +375,20 @@ module Zipper : sig @since NEXT_RELEASE *) val drop_after : 'a t -> 'a t - (** Drop every element on the "right" (calling {!right} then will do nothing). + (** Drop every element on the "right" (calling {!right} then will do nothing), + keeping the focused element, if any. @since NEXT_RELEASE *) + + val drop_after_and_focused : 'a t -> 'a t + (** Drop every element on the "right" (calling {!right} then will do nothing), + {i including} the focused element if it is present. + @since NEXT_RELEASE *) + + (*$= + ([1], [2]) (Zipper.drop_after ([1], [2;3])) + ([1], []) (Zipper.drop_after ([1], [])) + ([1], []) (Zipper.drop_after_and_focused ([1], [2;3])) + *) end (** {2 References on Lists}