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 t
Array 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 t
val length : _ t -> int
val singleton : 'a -> 'a t
val doubleton : 'a -> 'a -> 'a t
val make : int -> 'a -> 'a t
make n x
makes an array ofn
timesx
.
val init : int -> (int -> 'a) -> 'a t
init n f
makes the array[| f 0; f 1; ... ; f (n-1) |]
.- raises Invalid_argument
if
n < 0
.
val get : 'a t -> int -> 'a
Access the element.
val sub : 'a t -> int -> int -> 'a t
sub a start len
returns a fresh array of length len, containing the elements fromstart
topstart + len - 1
of array a.Raises
Invalid_argument "Array.sub"
ifstart
andlen
do 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 t
val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t
val append : 'a t -> 'a t -> 'a t
val iter : ('a -> unit) -> 'a t -> unit
val iteri : (int -> 'a -> unit) -> 'a t -> unit
val foldi : ('a -> int -> 'b -> 'a) -> 'a -> 'b t -> 'a
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
val for_all : ('a -> bool) -> 'a t -> bool
val 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 printer
pp ~pp_start ~pp_stop ~pp_sep pp_item ppf a
formats the arraya
onppf
. Each element is formatted withpp_item
,pp_start
is called at the beginning,pp_stop
is called at the end,pp_sep
is called between each elements. By defaultspp_start
andpp_stop
does nothing andpp_sep
defaults to (fun out -> Format.fprintf out ",@ ").