Module CCZipper
List Zipper
- since
- 1.0
type 'a t
= 'a list * 'a list
The pair
l, r
represents the listList.rev_append l r
, but with the focus onr
val empty : 'a t
Empty zipper.
val is_empty : _ t -> bool
Empty zipper? Returns
true
iff the two lists are empty.
val to_list : 'a t -> 'a list
Convert the zipper back to a list.
to_list (l,r)
isList.rev_append l r
.
val to_rev_list : 'a t -> 'a list
Convert the zipper back to a reversed list. In other words,
to_list (l,r)
isList.rev_append r l
.
val make : 'a list -> 'a t
Create a zipper pointing at the first element of the list.
val left_exn : 'a t -> 'a t
Go to the left, or
- raises Invalid_argument
if the zipper is already at leftmost pos.
val right_exn : 'a t -> 'a t
Go to the right, or
- raises Invalid_argument
if the zipper is already at rightmost pos.
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.
val insert : 'a -> 'a t -> 'a t
Insert an element at the current position. If an element was focused,
insert x l
addsx
just before it, and focuses onx
.
val is_focused : _ t -> bool
Is the zipper focused on some element? That is, will
focused
return aSome v
?
val focused : 'a t -> 'a option
Return the focused element, if any.
focused zip = Some _
iffempty zip = false
.
val focused_exn : 'a t -> 'a
Return the focused element, or
- raises Not_found
if the zipper is at an end.