mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 19:55:31 -05:00
more functions in CCList.Zipper
This commit is contained in:
parent
b34986518d
commit
79f872daf4
2 changed files with 36 additions and 2 deletions
|
|
@ -833,10 +833,18 @@ module Zipper = struct
|
||||||
| x::l, r -> l, x::r
|
| x::l, r -> l, x::r
|
||||||
| [], r -> [], r
|
| [], r -> [], r
|
||||||
|
|
||||||
|
let left_exn = function
|
||||||
|
| x::l, r -> l, x::r
|
||||||
|
| [], _ -> invalid_arg "zipper.left_exn"
|
||||||
|
|
||||||
let right = function
|
let right = function
|
||||||
| l, x::r -> x::l, r
|
| l, x::r -> x::l, r
|
||||||
| l, [] -> l, []
|
| l, [] -> l, []
|
||||||
|
|
||||||
|
let right_exn = function
|
||||||
|
| l, x::r -> x::l, r
|
||||||
|
| _, [] -> invalid_arg "zipper.right_exn"
|
||||||
|
|
||||||
let modify f z = match z with
|
let modify f z = match z with
|
||||||
| l, [] ->
|
| l, [] ->
|
||||||
begin match f None with
|
begin match f None with
|
||||||
|
|
@ -874,7 +882,11 @@ module Zipper = struct
|
||||||
|
|
||||||
let drop_before (_, r) = [], r
|
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
|
end
|
||||||
|
|
||||||
(** {2 References on Lists} *)
|
(** {2 References on Lists} *)
|
||||||
|
|
|
||||||
|
|
@ -331,9 +331,19 @@ module Zipper : sig
|
||||||
val left : 'a t -> 'a t
|
val left : 'a t -> 'a t
|
||||||
(** Go to the left, or do nothing if the zipper is already at leftmost pos *)
|
(** 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
|
val right : 'a t -> 'a t
|
||||||
(** Go to the right, or do nothing if the zipper is already at rightmost pos *)
|
(** 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
|
val modify : ('a option -> 'a option) -> 'a t -> 'a t
|
||||||
(** Modify the current element, if any, by returning a new element, or
|
(** Modify the current element, if any, by returning a new element, or
|
||||||
returning [None] if the element is to be deleted *)
|
returning [None] if the element is to be deleted *)
|
||||||
|
|
@ -365,8 +375,20 @@ module Zipper : sig
|
||||||
@since NEXT_RELEASE *)
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val drop_after : 'a t -> 'a t
|
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 *)
|
@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
|
end
|
||||||
|
|
||||||
(** {2 References on Lists}
|
(** {2 References on Lists}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue