Module Base__.Linked_queue
- type 'a t- = 'a Base__.Import.Caml.Queue.t
include Base.Sexpable.S1 with type 'a t := 'a t
- val t_of_sexp : (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a t
- val sexp_of_t : ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t
include Base.Indexed_container.S1 with type 'a t := 'a t
include Base.Container.S1
- val mem : 'a t -> 'a -> equal:('a -> 'a -> bool) -> bool
- Checks whether the provided element is there, using - equal.
- val length : 'a t -> int
- val is_empty : 'a t -> bool
- val iter : 'a t -> f:('a -> unit) -> unit
- val fold : 'a t -> init:'accum -> f:('accum -> 'a -> 'accum) -> 'accum
- fold t ~init ~freturns- f (... f (f (f init e1) e2) e3 ...) en, where- e1..enare the elements of- t
- val fold_result : 'a t -> init:'accum -> f:('accum -> 'a -> ('accum, 'e) Base.Result.t) -> ('accum, 'e) Base.Result.t
- fold_result t ~init ~fis a short-circuiting version of- foldthat runs in the- Resultmonad. If- freturns an- Error _, that value is returned without any additional invocations of- f.
- val fold_until : 'a t -> init:'accum -> f:('accum -> 'a -> ('accum, 'final) Base__.Container_intf.Continue_or_stop.t) -> finish:('accum -> 'final) -> 'final
- fold_until t ~init ~f ~finishis a short-circuiting version of- fold. If- freturns- Stop _the computation ceases and results in that value. If- freturns- Continue _, the fold will proceed. If- fnever returns- Stop _, the final result is computed by- finish.- Example: - type maybe_negative = | Found_negative of int | All_nonnegative of { sum : int } (** [first_neg_or_sum list] returns the first negative number in [list], if any, otherwise returns the sum of the list. *) let first_neg_or_sum = List.fold_until ~init:0 ~f:(fun sum x -> if x < 0 then Stop (Found_negative x) else Continue (sum + x)) ~finish:(fun sum -> All_nonnegative { sum }) ;; let x = first_neg_or_sum [1; 2; 3; 4; 5] val x : maybe_negative = All_nonnegative {sum = 15} let y = first_neg_or_sum [1; 2; -3; 4; 5] val y : maybe_negative = Found_negative -3
- val exists : 'a t -> f:('a -> bool) -> bool
- Returns - trueif and only if there exists an element for which the provided function evaluates to- true. This is a short-circuiting operation.
- val for_all : 'a t -> f:('a -> bool) -> bool
- Returns - trueif and only if the provided function evaluates to- truefor all elements. This is a short-circuiting operation.
- val count : 'a t -> f:('a -> bool) -> int
- Returns the number of elements for which the provided function evaluates to true. 
- val sum : (module Base__.Container_intf.Summable with type t = 'sum) -> 'a t -> f:('a -> 'sum) -> 'sum
- Returns the sum of - f ifor all- iin the container.
- val find : 'a t -> f:('a -> bool) -> 'a option
- Returns as an - optionthe first element for which- fevaluates to true.
- val find_map : 'a t -> f:('a -> 'b option) -> 'b option
- Returns the first evaluation of - fthat returns- Some, and returns- Noneif there is no such element.
- val to_list : 'a t -> 'a list
- val to_array : 'a t -> 'a array
- val min_elt : 'a t -> compare:('a -> 'a -> int) -> 'a option
- Returns a minimum (resp maximum) element from the collection using the provided - comparefunction, or- Noneif the collection is empty. In case of a tie, the first element encountered while traversing the collection is returned. The implementation uses- foldso it has the same complexity as- fold.
- val max_elt : 'a t -> compare:('a -> 'a -> int) -> 'a option
- val foldi : ('a t, 'a, _) Base__.Indexed_container_intf.foldi
- val iteri : ('a t, 'a) Base__.Indexed_container_intf.iteri
- val existsi : 'a t -> f:(int -> 'a -> bool) -> bool
- val for_alli : 'a t -> f:(int -> 'a -> bool) -> bool
- val counti : 'a t -> f:(int -> 'a -> bool) -> int
- val findi : 'a t -> f:(int -> 'a -> bool) -> (int * 'a) option
- val find_mapi : 'a t -> f:(int -> 'a -> 'b option) -> 'b option
- val singleton : 'a -> 'a t
- singleton areturns a queue with one element.
- val of_list : 'a list -> 'a t
- of_list listreturns a queue- twith the elements of- listin the same order as the elements of- list(i.e. the first element of- tis the first element of the list).
- val of_array : 'a array -> 'a t
- val init : int -> f:(int -> 'a) -> 'a t
- init n ~fis equivalent to- of_list (List.init n ~f).
- val enqueue : 'a t -> 'a -> unit
- enqueue t aadds- ato the end of- t.
- val enqueue_all : 'a t -> 'a list -> unit
- enqueue_all t listadds all elements in- listto- tin order of- list.
- val dequeue : 'a t -> 'a option
- dequeue tremoves and returns the front element of- t, if any.
- val dequeue_exn : 'a t -> 'a
- val peek : 'a t -> 'a option
- peek treturns but does not remove the front element of- t, if any.
- val map : 'a t -> f:('a -> 'b) -> 'b t
- val mapi : 'a t -> f:(int -> 'a -> 'b) -> 'b t
- val concat_map : 'a t -> f:('a -> 'b list) -> 'b t
- Creates a new queue with elements equal to - List.concat_map ~f (to_list t).
- val concat_mapi : 'a t -> f:(int -> 'a -> 'b list) -> 'b t
- val filter_map : 'a t -> f:('a -> 'b option) -> 'b t
- filter_mapcreates a new queue with elements equal to- List.filter_map ~f (to_list t).
- val filter_mapi : 'a t -> f:(int -> 'a -> 'b option) -> 'b t
- val filter : 'a t -> f:('a -> bool) -> 'a t
- filteris like- filter_map, except with- List.filter.
- val filteri : 'a t -> f:(int -> 'a -> bool) -> 'a t
- val filter_inplace : 'a t -> f:('a -> bool) -> unit
- filter_inplace t ~fremoves all elements of- tthat don't satisfy- f. If- fraises,- tis unchanged. This is inplace in that it modifies- t; however, it uses space linear in the final length of- t.
- val filteri_inplace : 'a t -> f:(int -> 'a -> bool) -> unit
- val create : unit -> _ t
- create ()returns an empty queue.