summaryrefslogtreecommitdiff
path: root/lib/zipper.mli
diff options
context:
space:
mode:
authorFederico Igne <undyamon@disroot.org>2024-01-28 23:40:30 +0100
committerFederico Igne <undyamon@disroot.org>2024-01-28 23:40:30 +0100
commit05e1cc51b2fb0824580925b55319377305105c44 (patch)
treef1bdc53ba8e312e764e7aa0765e1a6c72dd1c318 /lib/zipper.mli
parentf46d6661a8f33730c17cceb7e2885e789d6123d8 (diff)
downloadsandy-05e1cc51b2fb0824580925b55319377305105c44.tar.gz
sandy-05e1cc51b2fb0824580925b55319377305105c44.zip
feat(zipper): add option to not move past last element when moving right
Diffstat (limited to 'lib/zipper.mli')
-rw-r--r--lib/zipper.mli26
1 files changed, 16 insertions, 10 deletions
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
46val is_far_left : 'a zipper -> bool 46val is_far_left : 'a zipper -> bool
47(** Return whether the cursor is at the beginning of the zipper. *) 47(** Return whether the cursor is at the beginning of the zipper. *)
48 48
49val is_far_right : 'a zipper -> bool 49val is_far_right : ?by_one:bool -> 'a zipper -> bool
50(** Return whether the cursor is at the end of the zipper. *) 50(** Return whether the cursor is at the end of the zipper.
51 If [by_one] is [true], the cursor is considered at the far right
52 even when pointing {b to} the last element of the sequence. *)
51 53
52val is_empty : 'a zipper -> bool 54val is_empty : 'a zipper -> bool
53(** Return whether the zipper is empty. *) 55(** Return whether the zipper is empty. *)
@@ -79,26 +81,30 @@ val left_while : ('a -> bool) -> 'a zipper -> 'a zipper
79val far_left : 'a zipper -> 'a zipper 81val far_left : 'a zipper -> 'a zipper
80(** Move the cursor to the left, as much as possible. *) 82(** Move the cursor to the left, as much as possible. *)
81 83
82val right : 'a zipper -> 'a zipper 84val right : ?by_one:bool -> 'a zipper -> 'a zipper
83(** Move the cursor one step to the right, if possible. 85(** Move the cursor one step to the right, if possible. If [by_one] is
86 [true], the cursor won't move past the last element.
84 Calling [right z], 87 Calling [right z],
85 88
86 - if [z] is [([3; 2; 1], [4; 5])], the result is [([4; 3; 2; 1], [5])], 89 - if [z] is [([3; 2; 1], [4; 5])], the result is [([4; 3; 2; 1], [5])],
87 - if [z] is [([1; 2; 3], [])], the result is [([1; 2; 3], [])]. 90 - if [z] is [([1; 2; 3], [])], the result is [([1; 2; 3], [])].
88 *) 91 *)
89 92
90val right_while : ('a -> bool) -> 'a zipper -> 'a zipper 93val right_while : ?by_one:bool -> ('a -> bool) -> 'a zipper -> 'a zipper
91(** [right_while f z] moves the cursor in [z] to the right as long as 94(** [right_while f z] moves the cursor in [z] to the right as long as
92 the predicate [f] is [true] when applied to the focus, or the right 95 the predicate [f] is [true] when applied to the focus, or the right
93 end of the zipper is reached. *) 96 end of the zipper is reached. If [by_one] is [true], the cursor won't
97 move past the last element. *)
94 98
95val far_right : 'a zipper -> 'a zipper 99val far_right : ?by_one:bool -> 'a zipper -> 'a zipper
96(** Move the cursor to the right, as much as possible. *) 100(** Move the cursor to the right, as much as possible. If [by_one] is
101 [true], the cursor won't move past the last element.*)
97 102
98val goto : int -> 'a zipper -> 'a zipper 103val goto : ?by_one:bool -> int -> 'a zipper -> 'a zipper
99(** Move the cursor to a specific (absolute) position in the zipper. 104(** Move the cursor to a specific (absolute) position in the zipper.
100 Depending on the current position, it either moves the cursor 105 Depending on the current position, it either moves the cursor
101 forward or backwards, without crossing the zipper boundaries. *) 106 forward or backwards, without crossing the zipper boundaries. If
107 [by_one] is [true], the cursor won't move past the last element. *)
102 108
103(** {1 Changes at the cursor} *) 109(** {1 Changes at the cursor} *)
104 110