package batteries
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=1bcb27dfbd130eb057561196ef851649
sha512=2a56611b09a5f1cba6457539f8b6bc87a5f2a5454b36cdb39f6e0d6a5dac6db179aab1ba87c74dd49cc41df31a9a96feb349028ea41df7371ecb47f4d9dfafc4
doc/batteries.unthreaded/BatRefList/index.html
Module BatRefList
Reference on lists.
RefList is a extended set of functions that manipulate list references.
val empty : unit -> 'a tReturns a new empty ref list
val is_empty : 'a t -> boolReturn true if a ref list is empty
val clear : 'a t -> unitRemoves all elements
val length : 'a t -> intReturns the number of elements - O(n)
val copy_list : dst:'a t -> src:'a list -> unitMakes a copy of a list - O(1)
val of_list : 'a list -> 'a tCreates a ref list from a list - O(1)
val to_list : 'a t -> 'a listReturns the current elements as a list - O(1)
Creates a ref list from an enumeration, going from last to first
Returns an enumeration of current elements in the ref list, going from last to first
val add : 'a t -> 'a -> unitAdds an element at the end - O(n)
val push : 'a t -> 'a -> unitAdds an element at the head - O(1)
val add_sort : cmp:('a -> 'a -> int) -> 'a t -> 'a -> unitAdds an element in a sorted list, using the given comparator.
val first : 'a t -> 'aReturns the first element or raises Empty_list if the ref list is empty
val last : 'a t -> 'aReturns the last element - O(n) or raises Empty_list if the ref list is empty
val pop : 'a t -> 'aRemoves and returns the first element or raises Empty_list if the ref list is empty
val npop : 'a t -> int -> 'a listRemoves and returns the n first elements or raises Empty_list if the ref list does not contain enough elements
val hd : 'a t -> 'asame as first
Returns a ref list containing the same elements but without the first one or raises Empty_list if the ref list is empty
val rev : 'a t -> unitReverses the ref list - O(n)
Functional Operations
val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'aList.fold_left f a (ref [b0; b1; ...; bn]) is f (... (f (f a b0) b1) ...) bn.
val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'bList.fold_right f (ref [a0; a1; ...; an]) b is f a0 (f a1 (... (f an b) ...)). Tail-recursive.
val iter : ('a -> unit) -> 'a t -> unitApply the given function to all elements of the ref list, in respect with the order of the list
val find : ('a -> bool) -> 'a t -> 'aFind the first element matching the specified predicate raise Not_found if no element is found
val rfind : ('a -> bool) -> 'a t -> 'aFind the first element in the reversed ref list matching the specified predicate raise Not_found if no element is found
val find_exn : ('a -> bool) -> exn -> 'a t -> 'aSame as find but takes an exception to be raised when no element is found as additional parameter.
val find_exc : ('a -> bool) -> exn -> 'a t -> 'aAlias for find_exn.
val exists : ('a -> bool) -> 'a t -> boolReturn true if an element matches the specified predicate
val for_all : ('a -> bool) -> 'a t -> boolReturn true if all elements match the specified predicate
Apply a function to all elements and return the ref list constructed with the function returned values
val transform : ('a -> 'a) -> 'a t -> unittransform all elements in the ref list using a function.
val map_list : ('a -> 'b) -> 'a t -> 'b listApply a function to all elements and return the list constructed with the function returned values
val sort : cmp:('a -> 'a -> int) -> 'a t -> unitSort elements using the specified comparator
val filter : ('a -> bool) -> 'a t -> unitRemove all elements that do not match the specified predicate
val remove : 'a t -> 'a -> unitRemove an element from the ref list raise Not_found if the element is not found
val remove_if : ('a -> bool) -> 'a t -> unitRemove the first element matching the specified predicate raise Not_found if no element has been removed
val remove_all : 'a t -> 'a -> unitRemove all elements equal to the specified element from the ref list
Boilerplate code
module Index : sig ... endFunctions that operate on the element at index i in a list (with indices starting from 0).