Mutability is rw
(read-write) or ro
(read-only).
Create a new vector, using the given value as a filler.
Hint to the vector that it should have at least the given capacity.
capacity v = 0
, used as a filler
element for the underlying array (see create_with).Hint to the vector that it should have at least the given capacity.
Just a hint, will not be enforced if the vector is empty and init
is not provided.
Shrink to the given size (remove elements above this size). Does nothing if the parameter is bigger than the current size.
Sort the vector, returning a copy of it that is sorted w.r.t the given ordering. The vector itself is unchanged.
Filter elements from the vector. filter p v
leaves v
unchanged but
returns a new vector that only contains elements of v
satisfying p
.
val exists : ('a ‑> bool) ‑> ('a, _) t ‑> bool
Existential test (is there an element that satisfies the predicate?).
val for_all : ('a ‑> bool) ‑> ('a, _) t ‑> bool
Universal test (do all the elements satisfy the predicate?).
val find_exn : ('a ‑> bool) ‑> ('a, _) t ‑> 'a
Find an element that satisfies the predicate, or
val find_map : ('a ‑> 'b option) ‑> ('a, _) t ‑> 'b option
find_map f v
returns the first Some y = f x
for x
in v
,
or None
if f x = None
for each x
in v
.
Like flat_map, but using list for intermediate collections.
val get : ('a, _) t ‑> int ‑> 'a
Access element by its index, or
Remove the n-th
element of the vector. Does NOT preserve the order
of the elements (might swap with the last element).
val rev_iter : ('a ‑> unit) ‑> ('a, _) t ‑> unit
rev_iter f a
is the same as iter f (rev a)
, only more efficient.
Access the underlying shared array (do not modify!).
unsafe_get_array v
is longer than size v
, but elements at higher
index than size v
are undefined (do not access!).
val (--) : int ‑> int ‑> (int, 'mut) t
Range of integers, either ascending or descending (both included,
therefore the result is never empty).
Example: 1 -- 10
returns the vector [1;2;3;4;5;6;7;8;9;10]
.
val (--^) : int ‑> int ‑> (int, 'mut) t
Range of integers, either ascending or descending, but excluding right.
Example: 1 --^ 10
returns the vector [1;2;3;4;5;6;7;8;9]
.
val of_array : 'a array ‑> ('a, 'mut) t
of_array a
returns a vector corresponding to the array a
. Operates in O(n)
time.
val of_list : 'a list ‑> ('a, 'mut) t
to_seq_rev v
returns the sequence of elements of v
in reverse order,
that is, the last elements of v
are iterated on first.