module Core_array: sig
.. end
A better Array module. If you open Core.Std, you get this as your Array module
in place of the standard Array module.
type 'a
t = 'a array
include Binable.S1
include Container.S1
include Sexpable.S1
val get : 'a array -> int -> 'a
val set : 'a array -> int -> 'a -> unit
val create : int -> 'a -> 'a array
val init : int -> f:(int -> 'a) -> 'a array
val make_matrix : dimx:int -> dimy:int -> 'a -> 'a array t
val append : 'a array -> 'a array -> 'a array
val concat : 'a array list -> 'a array
val sub : 'a array -> pos:int -> len:int -> 'a array
val copy : 'a array -> 'a array
val fill : 'a array -> pos:int -> len:int -> 'a -> unit
val blit : src:'a array -> src_pos:int -> dst:'a array -> dst_pos:int -> len:int -> unit
val of_list : 'a list -> 'a array
val map : f:('a -> 'b) -> 'a array -> 'b t
val iteri : f:(int -> 'a -> unit) -> 'a array -> unit
val mapi : f:(int -> 'a -> 'b) -> 'a array -> 'b t
val fold_left : f:('a -> 'b -> 'a) -> init:'a -> 'b t -> 'a
val fold_right : f:('a -> 'b -> 'b) -> 'a t -> init:'b -> 'b
val sort : cmp:('a -> 'a -> int) -> 'a array -> unit
val stable_sort : cmp:('a -> 'a -> int) -> 'a array -> unit
val fast_sort : cmp:('a -> 'a -> int) -> 'a array -> unit
----------------------------------------------------------------------
Extensions
----------------------------------------------------------------------
val cartesian_product : 'a array -> 'b array -> ('a * 'b) array
val normalize : 'a array -> int -> int
normalize array index
returns a new index into the array such that if index is less
than zero, the returned index will "wrap around" -- i.e. array.(normalize array (-1))
returns the last element of the array.
val slice : 'a array -> int -> int -> 'a array
slice array start stop
returns a fresh array including elements array.(start)
through
array.(stop-1)
with the small tweak that the start and stop positions are normalized
and a stop index of 0 means the same thing a stop index of Array.length array
. In
summary, it's like the slicing in Python or Matlab.
val nget : 'a array -> int -> 'a
Array access with normalize
d index.
val nset : 'a array -> int -> 'a -> unit
Array modification with normalize
d index.
val filter_opt : 'a option array -> 'a array
filter_opt array
returns a new array where None
entries are omitted and Some x
entries are replaced with x
. Note that this changes the index at which elements
will appear.
val filter_map : f:('a -> 'b option) -> 'a array -> 'b array
filter_map ~f array
maps f
over array
and filters None
out of the results.
val filter_mapi : f:(int -> 'a -> 'b option) -> 'a array -> 'b array
Same as filter_map
but uses Array.mapi
.
val map2 : f:('a -> 'b -> 'c) -> 'a array -> 'b array -> 'c t
val filter : f:('a -> bool) -> 'a array -> 'a array
filter ~f array
removes the elements for which f
returns false.
val filteri : f:(int -> 'a -> bool) -> 'a array -> 'a array
Like filter
except f
also receives the index.
val swap : 'a array -> int -> int -> unit
swap arr i j
swaps the value at index i
with that at index j
.
val mem : 'a -> 'a array -> bool
mem el arr
returns true iff arr.(i) = el
for some i
val rev : 'a array -> unit
rev ar
reverses ar
in place
val replace : 'a t -> int -> f:('a -> 'a) -> unit
replace t i ~f
= t.(i) <- f (t.(i))
.
val replace_all : 'a t -> f:('a -> 'a) -> unit
modifies an array in place -- ar.(i)
will be set to f(ar.(i))
val find_exn : 'a array -> f:('a -> bool) -> 'a
find_exn f t
returns in first a
in t
for which f t.(i)
is true.
It raises Not_found
if there is no such a
.
val findi : 'a array -> f:('a -> bool) -> int option
findi f ar
returns in first index i
of ar
for which f ar.(i)
is true
val findi_exn : 'a array -> f:('a -> bool) -> int
findi_exn f ar
returns in first index i
of ar
for which f ar.(i)
is
true. It raises Not_found
if there is no such element.
val reduce : f:('a -> 'a -> 'a) -> 'a array -> 'a
reduce f [a1; ...; an]
is f (... (f (f a1 a2) a3) ...) an
.
val best : f:('a -> 'a -> 'a) -> 'a array -> 'a
best
is an alias for reduce
.
val permute : ?random_state:Random.State.t -> 'a array -> unit
permute ar
randomly permutes ar
in place
val combine : 'a array -> 'b array -> ('a * 'b) array
combine ar
combines two arrays to an array of pairs.
val sorted_copy : 'a array -> cmp:('a -> 'a -> int) -> 'a array
sorted_copy ar cmp
returns a shallow copy of ar
that is sorted. Similar to
List.sort
val last : 'a array -> 'a
module Infix: sig
.. end