package vec
Install
Dune Dependency
Authors
Maintainers
Sources
md5=a20e2d8408a96e76f10349b9a4f3ac88
sha512=ca7b54ae412d5a95c66843bdec0ca5436216e55052fba463d29e7a813ba5b9b1af0e54024b95baccb6c75dd0c42cb74c3e0c8aa5a52abb8d71b344cb2d171054
doc/vec/Vec/index.html
Module Vec
Source
Mutable dynamic arrays
The 'p type parameter is a phantom type parameter that represents the vector's mutability.
It is [`R | `W]
for read-write vectors, [`R]
for read-only vectors, or [`W]
for write-only vectors.
The default growth rate of newly-created vectors.
Creating vectors
Constructs a vector with the specified growth rate and capacity.
Growth rate defaults to default_growth_rate
.
Capacity defaults to 0.
Constructs a vector containing all numbers in the specified range.
Returns a singleton vector containing the specified item. (Applicative functor pure
operation)
Restricting permissions
Reinterprets the vector as a read-only vector.
Reinterprets the vector as a write-only vector.
Basic properties
Ensures the vector's buffer has at least as many free slots as the specified value.
Sets the growth rate of vector to the specified value.
Ensures the vector's growth rate is at least as great as the specified value.
Accessing elements
Gets the value in the vector at the specified index. Returns None if the index is out of range.
Sets the value in the vector at the specified index to the specified value. Returns false if the index is out of range.
Gets the value in the vector at the specified index.
Sets the value in the vector at the specified index to the specified value.
Returns the first element of the vector that satisfies the predicate, or None
.
Returns the first element of the vector that satisfies the predicate.
Conversions
Returns a string representation of the vector, using the specified function to format each value.
Modifying vectors
Shrinks the vector's internal buffer to only be as large as the vector's length.
Inserts an item into the vector at the specified index.
Removes and returns the item at the specified index.
Removes the item at the specified index, without returning it.
Transformations
Maps the specified function over the vector, returning a new vector. (Functor map
operation)
Like map
, but the function also takes the item's index as a parameter.
Like map
, but the transformation is done in-place.
Like map
, but flattens the result. (Monad bind
operation)
Returns a new vector that contains all the items in the specified vector, but in reverse order.
Filters & folds
Returns a new vector containing only the items from the first vector that satisfy the specified predicate.
Like filter
, but the predicate also takes the item's index as a parameter.
Performs a filter in-place, based on the specified predicate.
Folds the specified function and default value over the array, from left to right.
Folds the specified function and default value over the array, from right to left.
Combining vectors
Concatenates the two vectors into a new vector.
Appends the second vector to the first vector in-place.
Cartesian product of 2 vectors. (Equivalent to liftA2 (,)
)
Maps the specified function over all combinations of tuples from the 2 vectors, returning a new vector. (Applicative functor liftA2
operation
Applies every function from the first vector to every value from the second vector, returning a new vector. (Applicatve functor ap
operation)
Flattens nested vectors into a single, one-dimensional vector. (Monad join
operation)
Zips the two vectors together.
Zips the two vectors together, using the specified function to combine values.
Querying vectors
Returns true
if any item in the vector satisfies the specified predicate.
Returns true
if all items in the vector satisfy the specified predicate.
Returns true
if the specified item exists in the vector. Uses structural equality.
Returns true
if the specified item exists in the vector. Uses physical equality.
Sorting
Sorts the vector using the specified comparison function.
Equality and comparison
Compares two vectors for equality, using the specified equality function for elements.
Compares two vectors lexicographically.
Compares two vectors lexicographically, using the specified comparison function for elements.
Iteration
Applies the specified function to each item in the vector.
Like iter
, but the function also takes the item's index as a parameter.
Infix operators
Monadic syntax
Provides support for OCaml 4.08's binding operator syntax.