package travesty

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Zipper.PlainSource

Plain is a basic list zipper, without specialised functionality.

include Zipper_types.S_non_monadic
Sourcetype 'a t

The opaque type of zippers.

include Sexplib0.Sexpable.S1 with type 'a t := 'a t
Sourceval t_of_sexp : (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a t
Sourceval sexp_of_t : ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t

Construction and destruction

Sourceval make : left:'a Base.list -> right:'a Base.list -> 'a t

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.

Sourceval of_list : 'a Base.list -> 'a t

of_list xs converts a list xs to a fully-rewound zipper.

It is equivalent to make with an empty left.

Sourceval to_list : 'a t -> 'a Base.list

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

Sourceval left_list : 'a t -> 'a Base.list

left_list zipper gets the raw left list of the zipper: all of the already-processed items in reverse order.

Sourceval right_list : 'a t -> 'a Base.list

right_list zipper gets the right list of the zipper: all of the not-yet-processed items in forwards order.

Sourceval to_two_lists : 'a t -> 'a Base.list * 'a Base.list

to_two_lists zipper is (left_list zipper, right_list zipper).

Sourceval left_length : 'a t -> Base.int

left_length zipper gets the length of zipper's left list.

Sourceval right_length : 'a t -> Base.int

right_length zipper gets the length of zipper's right list.

Predicates

Sourceval is_at_start : 'a t -> Base.bool

is_at_start zipper tests whether zipper's left list is empty.

Sourceval is_at_end : 'a t -> Base.bool

is_at_end zipper tests whether zipper's right list is empty.

Pushing

Sourceval push : 'a t -> value:'a -> 'a t

push zipper ~value pushes value into zipper at the cursor. The current cursor becomes the second item in the right list, and so on.

Sourceval push_left : 'a t -> value:'a -> 'a t

push_left zipper ~value pushes value into zipper just to the left of the cursor.

Peeking and popping

Sourceval peek_opt : ?steps:Base.int -> 'a t -> 'a Base.option

peek_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.

Sourceval pop : 'a t -> ('a * 'a t) Base.Or_error.t

pop 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.

Sourceval pop_opt : 'a t -> ('a * 'a t) Base.option

pop_opt zipper behaves as pop, but returns None if zipper has no cursor and Some (a, zipper') otherwise.

Sourceval map_head : 'a t -> f:('a -> 'a Base.option) -> 'a t

map_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

Sourceval step : ?steps:Base.int -> 'a t -> 'a t Base.Or_error.t

step ?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.

Sourcemodule On_monad (M : Base.Monad.S) : Zipper_types.S_monadic with type 'a t := 'a t and module M := M

On_monad provides various zipper operations parametrised by a monad.

Sourcemodule On_ident : sig ... end

On_ident is On_monad specialised to the identity monad.

Sourcemodule On_error : sig ... end

On_error is On_monad specialised to the error monad.

Sourcemodule On_option : sig ... end

On_option is On_monad specialised to the option monad.

OCaml

Innovation. Community. Security.