Module CCImmutArray
Immutable Arrays
Purely functional use of arrays. Update is costly, but reads are very fast. Sadly, it is not possible to make this type covariant without using black magic.
- since
- 0.17
type 'a tArray of values of type 'a. The underlying type really is an array, but it will never be modified.
It should be covariant but OCaml will not accept it.
val empty : 'a tval length : _ t -> intval singleton : 'a -> 'a tval doubleton : 'a -> 'a -> 'a tval make : int -> 'a -> 'a tmake n xmakes an array ofntimesx.
val init : int -> (int -> 'a) -> 'a tinit n fmakes the array[| f 0; f 1; ... ; f (n-1) |].- raises Invalid_argument
if
n < 0.
val get : 'a t -> int -> 'aAccess the element.
val sub : 'a t -> int -> int -> 'a tsub a start lenreturns a fresh array of length len, containing the elements fromstarttopstart + len - 1of array a.Raises
Invalid_argument "Array.sub"ifstartandlendo not designate a valid subarray of a; that is, if start < 0, or len < 0, or start + len > Array.length a.- since
- 1.5
val map : ('a -> 'b) -> 'a t -> 'b tval mapi : (int -> 'a -> 'b) -> 'a t -> 'b tval append : 'a t -> 'a t -> 'a tval iter : ('a -> unit) -> 'a t -> unitval iteri : (int -> 'a -> unit) -> 'a t -> unitval foldi : ('a -> int -> 'b -> 'a) -> 'a -> 'b t -> 'aval fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'aval for_all : ('a -> bool) -> 'a t -> boolval exists : ('a -> bool) -> 'a t -> bool