package travesty
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9c7b3803620c54496a35983285242ec8e06a5efb1baa3523384d7184b7e9fab7
sha512=991646fe5bb899971d3f8c00432d4df6c45dbd81cbff885b28d30d9c228e5df61f1e8d61aadc164ec35c448093abb34fd7a7d571e1cdf4d3af25579bf400f167
doc/travesty.containers/Travesty_containers/Zipper/Make_marked/index.html
Module Zipper.Make_marked
Make_marked makes a marked zipper from a Basic_mark.
Parameters
module Mark : Zipper_types.Basic_markSignature
include Zipper_types.S_marked_non_monadic with type mark := Mark.t
include Zipper_types.S_non_monadic
include Ppx_sexp_conv_lib.Sexpable.S1 with type 'a t := 'a t
val t_of_sexp : (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a tval sexp_of_t : ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.tConstruction and destruction
make ~left ~right constructs a zipper with left list left and right list right.
These lists go directly into the zipper itself, so left, if non-empty, should be in the reverse order to how it should appear when fully rewound.
of_list xs converts a list xs to a fully-rewound zipper.
It is equivalent to make with an empty left.
to_list zipper returns the list of _all_ items in the zipper, including those in the left list.
All items appear in the same order that they would take in the right list if the zipper was fully rewound. In other words, the left list appears first (in reverse order), followed by the right list (in forwards order).
To get only the items in the right list, use right_list; to get only the items in the left list (reversed), use left_list.
Querying the left and right lists
left_list zipper gets the raw left list of the zipper: all of the already-processed items in reverse order.
right_list zipper gets the right list of the zipper: all of the not-yet-processed items in forwards order.
to_two_lists zipper is (left_list zipper, right_list zipper).
Predicates
Pushing
push zipper ~value pushes value into zipper at the cursor. The current cursor becomes the second item in the right list, and so on.
push_left zipper ~value pushes value into zipper just to the left of the cursor.
Peeking and popping
val peek_opt : ?steps:Base.int -> 'a t -> 'a Base.optionpeek_opt ?steps zipper retrieves the cursor value without popping it from the zipper. If the cursor is empty, None is returned.
If steps is given, it shifts the effective cursor steps places forwards.
val pop : 'a t -> ('a * 'a t) Base.Or_error.tpop zipper returns an error if zipper has no cursor, or Ok (a, zipper') where a is zipper's cursor and zipper' is the new zipper formed by removing a.
val pop_opt : 'a t -> ('a * 'a t) Base.optionpop_opt zipper behaves as pop, but returns None if zipper has no cursor and Some (a, zipper') otherwise.
val map_head : 'a t -> f:('a -> 'a Base.option) -> 'a tmap_head zipper ~f maps f across the cursor of zipper, if it exists, and replaces the cursor with the result (or drops it if f returns None).
Movement
val step : ?steps:Base.int -> 'a t -> 'a t Base.Or_error.tstep ?steps zipper ~on_empty takes one or more steps across zipper. The number of steps defaults to 1 (forwards), but can be given by steps; negative numbers step backwards through the zipper. If the number of steps exceeds the bounds of the zipper, an error is returned.
val mark : 'a t -> mark:Mark.t -> 'a t Base.Or_error.tmark zipper ~mark marks the cursor with mark, and returns the marked-up zipper.
If the cursor is empty, an error is returned.
val recall : 'a t -> mark:Mark.t -> 'a t Base.Or_error.trecall zipper ~mark rewinds zipper until the cursor is on an element previously marked with mark.
If recall runs out of left-list to rewind before finding mark, an error is returned.
val fold_until :
'a t ->
f:
('acc ->
'a ->
'a t ->
(Mark.t, 'a, 'acc, 'final) Zipper_types.fold_outcome) ->
init:'acc ->
finish:('acc -> 'a t -> 'final) ->
'finalfold_until zipper ~f ~init ~finish behaves conceptually like List.fold_until, but folds f through the remaining elements of a zipper.
f receives the current accumulator, current cursor, and zipper with cursor popped at each stage. It can't directly modify the zipper mid-fold, but can influence the value of the final zipper provided to the finish continuation by using the various legs of fold_outcome.
val delete_to_mark : 'a t -> mark:Mark.t -> 'a t Base.Or_error.tdelete_to_mark zipper ~mark deletes every item in the left-list up to, and including, the element previously marked with mark.
If delete_to_mark runs out of left-list to rewind before finding mark, an error is returned.
module On_monad
(M : Base.Monad.S) :
Zipper_types.S_marked_monadic
with type 'a t := 'a t
and type mark := Mark.t
and module M := MOn_monad provides various marked zipper operations parametrised by a monad.
module On_ident : sig ... endOn_ident is On_monad specialised to the identity monad.
module On_error : sig ... endOn_error is On_monad specialised to the error monad.
module On_option : sig ... endOn_option is On_monad specialised to the option monad.