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
Conversions
IO
val pp : ?pp_start:unit printer -> ?pp_stop:unit printer -> ?pp_sep:unit printer -> 'a printer -> 'a t printerpp ~pp_start ~pp_stop ~pp_sep pp_item ppf aformats the arrayaonppf. Each element is formatted withpp_item,pp_startis called at the beginning,pp_stopis called at the end,pp_sepis called between each elements. By defaultspp_startandpp_stopdoes nothing andpp_sepdefaults to (fun out -> Format.fprintf out ",@ ").