Module Base.IarraySource

Sourcemodule type Operators = sig ... end
Sourcemodule type Public = sig ... end
Sourcetype ('a : any mod separable) t = 'a Basement.Stdlib_iarray_labels.t
include sig ... end
Sourceval compare : ('a : value_or_null mod separable). ('a -> 'a -> int) -> 'a t -> 'a t -> int
Sourceval compare__local : ('a : value_or_null mod separable). ('a @ local -> 'a @ local -> int) -> 'a t @ local -> 'a t @ local -> int
Sourceval equal : ('a : value_or_null mod separable). ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
Sourceval equal__local : ('a : value_or_null mod separable). ('a @ local -> 'a @ local -> bool) -> 'a t @ local -> 'a t @ local -> bool
Sourceval sexp_of_t : ('a : value_or_null mod separable). ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t
Sourceval sexp_of_t__stack : ('a : value_or_null mod separable). ('a @ local -> Sexplib0.Sexp.t @ local) -> 'a t @ local -> Sexplib0.Sexp.t @ local
Sourceval t_of_sexp : ('a : value_or_null mod separable). (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a t
Sourceval globalize : ('a : value_or_null mod separable). ('a @ local -> 'a) -> 'a t @ local -> 'a t
Sourceval t_sexp_grammar : ('a : value_or_null mod separable). 'a Sexplib0.Sexp_grammar.t -> 'a t Sexplib0.Sexp_grammar.t @@ portable
include sig ... end
include Ppx_hash_lib.Hashable.S1 with type 'a t := 'a t

Standard interfaces

include Binary_searchable.S1__local with type 'a t := 'a t

See Binary_search.binary_search in binary_search.ml

See Binary_search.binary_search_segmented in binary_search.ml

Sourceval binary_search_segmented : ?pos:int -> ?len:int -> 'a t -> segment_of:('a -> [ `Left | `Right ]) @ local -> [ `Last_on_left | `First_on_right ] -> int option @ local
include Indexed_container.S1_with_creators__''value_or_null''__stack with type ('a : any) t := 'a t
include Container.S1__''value_or_null''__stack with type ('a : any) t := 'a t
include sig ... end
include sig ... end

These are all like their equivalents in Container except that an index starting at 0 is added as the first argument to f.

Sourceval existsi : ('a : value_or_null mod separable) 'p1 'p2. ('a, 'p1, 'p2) {t}45/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a {elt}46/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> bool) @ local) @ local -> bool
Sourceval for_alli : ('a : value_or_null mod separable) 'p1 'p2. ('a, 'p1, 'p2) {t}45/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a {elt}46/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> bool) @ local) @ local -> bool
Sourceval counti : ('a : value_or_null mod separable) 'p1 'p2. ('a, 'p1, 'p2) {t}45/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a {elt}46/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> bool) @ local) @ local -> int
Sourceval iteri_until : ('a : value_or_null mod separable) 'p1 'p2 ('final : value_or_null). ('a, 'p1, 'p2) {t}45/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a {elt}46/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> (unit, 'final) Container.Continue_or_stop.t) @ local) @ local -> finish:(int -> 'final) @ local -> 'final
Sourceval find_mapi : ('a : value_or_null mod separable) 'p1 'p2 ('b : value_or_null). ('a, 'p1, 'p2) {t}45/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a {elt}46/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> 'b option) @ local) @ local -> 'b option
Sourceval foldi_until : ('a : value_or_null mod separable) 'p1 'p2 ('acc : value_or_null) ('final : value_or_null). ('a, 'p1, 'p2) {t}45/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> init:'acc -> f: (int -> ('acc -> ('a {elt}46/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> ('acc, 'final) Container.Continue_or_stop.t) @ local) @ local) @ local -> finish:(int -> ('acc -> 'final) @ local) @ local -> 'final
Sourceval findi : ('a : value_or_null mod separable) 'p1 'p2. ('a, 'p1, 'p2) t -> f:(int -> ('a elt -> bool) @ local) @ local -> (int * 'a elt) option
include Container.S1_with_creators__''value_or_null''__stack with type ('a : value_or_null mod separable) t := 'a t
include sig ... end
Sourceval is_empty : ('a : value_or_null mod separable) 'p1 'p2. 'a t @ local -> bool
Sourceval exists : ('a : value_or_null mod separable) 'p1 'p2. 'a t -> f:('a -> bool) @ local -> bool

Returns true if and only if there exists an element for which the provided function evaluates to true. This is a short-circuiting operation.

Sourceval count : ('a : value_or_null mod separable) 'p1 'p2. 'a t -> f:('a -> bool) @ local -> int

Returns the number of elements for which the provided function evaluates to true.

Sourceval find : ('a : value_or_null mod separable) 'p1 'p2. 'a t -> f:('a -> bool) @ local -> 'a option

Returns as an option the first element for which f evaluates to true.

Sourceval to_list : ('a : value_or_null mod separable) 'p1 'p2. 'a t -> 'a list
Sourceval min_elt : ('a : value_or_null mod separable) 'p1 'p2. 'a t -> compare:('a -> ('a -> int) @ local) @ local -> 'a option

Returns a min (resp. max) element from the collection using the provided compare function. In case of a tie, the first element encountered while traversing the collection is returned. The implementation uses fold so it has the same complexity as fold. Returns None iff the collection is empty.

Sourceval max_elt : ('a : value_or_null mod separable) 'p1 'p2. 'a t -> compare:('a -> ('a -> int) @ local) @ local -> 'a option
Sourceval sum : ('a : value_or_null mod separable) ('sum : value_or_null) 'p1 'p2. (module Container.Summable with type t = 'sum) -> 'a t -> f:('a -> 'sum) @ local -> 'sum

Returns the sum of f i for all i in the container. The order in which the elements will be summed is unspecified.

Sourceval iter_until : ('a : value_or_null mod separable) 'p1 'p2 ('final : value_or_null). 'a t -> f:('a -> (unit, 'final) Container.Continue_or_stop.t) @ local -> finish:(unit -> 'final) @ local -> 'final

iter_until t ~f ~finish is a short-circuiting version of iter. If f returns Stop x the computation ceases and returns x. If f always returns Continue () the final result is computed by finish.

Sourceval fold_result : ('a : value_or_null mod separable) 'p1 'p2 ('acc : value_or_null) 'e. 'a t -> init:'acc -> f:('acc -> ('a -> ('acc, 'e) result) @ local) @ local -> ('acc, 'e) result

fold_result t ~init ~f is a short-circuiting version of fold that runs in the Result monad. If f returns an Error _, that value is returned without any additional invocations of f.

Sourceval find_map : ('a : value_or_null mod separable) 'p1 'p2 ('b : value_or_null). 'a t -> f:('a -> 'b option) @ local -> 'b option

Returns the first evaluation of f that returns Some, and returns None if there is no such element.

include sig ... end
Sourceval fold_until : ('a : value_or_null mod separable) 'p1 'p2 ('acc : value_or_null) ('final : value_or_null). 'a t -> init:'acc -> f: ('acc -> ('a -> ('acc, 'final) Container.Continue_or_stop.t) @ local) @ local -> finish:('acc -> 'final) @ local -> 'final

fold_until t ~init ~f ~finish is a short-circuiting version of fold. If f returns Stop _ the computation ceases and results in that value. If f returns Continue _, the fold will proceed. If f never returns Stop _, the final result is computed by finish.

Example:

  type maybe_negative =
    | Found_negative of int
    | All_nonnegative of { sum : int }

  (** [first_neg_or_sum list] returns the first negative number in [list], if any,
      otherwise returns the sum of the list. *)
  let first_neg_or_sum =
    List.fold_until ~init:0
      ~f:(fun sum x ->
        if x < 0
        then Stop (Found_negative x)
        else Continue (sum + x))
      ~finish:(fun sum -> All_nonnegative { sum })
  ;;

  let x = first_neg_or_sum [1; 2; 3; 4; 5]
  val x : maybe_negative = All_nonnegative {sum = 15}

  let y = first_neg_or_sum [1; 2; -3; 4; 5]
  val y : maybe_negative = Found_negative -3
Sourceval mem : ('a : value_or_null mod separable) 'p1 'p2. 'a t -> 'a -> equal:('a -> ('a -> bool) @ local) @ local -> bool

Checks whether the provided element is there, using equal.

include sig ... end
Sourceval of_list : ('a : value_or_null mod separable) 'p1 'p2. 'a list -> 'a t
Sourceval append : ('a : value_or_null mod separable) 'p1 'p2. 'a t -> 'a t -> 'a t

E.g., append (of_list [a; b]) (of_list [c; d; e]) is of_list [a; b; c; d; e]

Sourceval concat : ('a : value_or_null mod separable) 'p1 'p2. 'a t t -> 'a t

Concatenates a nested container. The elements of the inner containers are concatenated together in order to give the result.

Sourceval filter : ('a : value_or_null mod separable) 'p1 'p2. 'a t -> f:('a -> bool) @ local -> 'a t

filter t ~f returns all the elements of t that satisfy the predicate f.

Sourceval partition_tf : ('a : value_or_null mod separable) 'p1 'p2. 'a t -> f:('a -> bool) @ local -> 'a t * 'a t

partition_tf t ~f returns a pair t1, t2, where t1 is all elements of t that satisfy f, and t2 is all elements of t that do not satisfy f. The "tf" suffix is mnemonic to remind readers that the result is (trues, falses).

include sig ... end
Sourceval filter_map : ('a : value_or_null mod separable) 'p1 'p2 ('b : value_or_null mod separable). 'a t -> f:('a -> 'b option) @ local -> 'b t

filter_map t ~f applies f to every x in t. The result contains every y for which f x returns Some y.

Sourceval concat_map : ('a : value_or_null mod separable) 'p1 'p2 ('b : value_or_null mod separable). 'a t -> f:('a -> 'b t) @ local -> 'b t

concat_map t ~f is equivalent to concat (map t ~f).

include sig ... end
Sourceval partition_map : ('a : value_or_null mod separable) 'p1 'p2 ('b : value_or_null mod separable) ('c : value_or_null mod separable). 'a t -> f:('a -> ('b, 'c) Base__.Either0.t) @ local -> 'b t * 'c t

partition_map t ~f partitions t according to f.

Sourceval filteri : ('a : value_or_null mod separable) 'p1 'p2. ('a, 'p1, 'p2) {t}365/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a {elt}366/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> bool) @ local) @ local -> ('a, 'p1, 'p2) {t}365/shadowed/(8f9e3060c4c689c937aa7d214ca25fca)
Sourceval partitioni_tf : ('a : value_or_null mod separable) 'p1 'p2. ('a, 'p1, 'p2) {t}365/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a {elt}366/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> bool) @ local) @ local -> ('a, 'p1, 'p2) {t}365/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) * ('a, 'p1, 'p2) {t}365/shadowed/(8f9e3060c4c689c937aa7d214ca25fca)

partitioni_tf t ~f is like partition_tf. Additionally, it passes the index as an argument.

Sourceval filter_mapi : ('a : value_or_null mod separable) 'p1 'p2 ('b : value_or_null mod separable). ('a, 'p1, 'p2) {t}365/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a {elt}366/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> 'b {elt}366/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) option) @ local) @ local -> ('b, 'p1, 'p2) {t}365/shadowed/(8f9e3060c4c689c937aa7d214ca25fca)

filter_mapi is like filter_map. Additionally, it passes in the index of each element as the first argument to the mapped function.

Sourceval concat_mapi : ('a : value_or_null mod separable) 'p1 'p2 ('b : value_or_null mod separable). ('a, 'p1, 'p2) {t}365/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a {elt}366/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> ('b, 'p1, 'p2) {t}365/shadowed/(8f9e3060c4c689c937aa7d214ca25fca)) @ local) @ local -> ('b, 'p1, 'p2) {t}365/shadowed/(8f9e3060c4c689c937aa7d214ca25fca)

concat_mapi t ~f is like concat_map. Additionally, it passes the index as an argument.

Sourceval partition_mapi : ('a : value_or_null mod separable) 'p1 'p2 ('b : value_or_null mod separable) ('c : value_or_null mod separable). ('a, 'p1, 'p2) {t}365/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> f: (int -> ('a {elt}366/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) -> ('b {elt}366/shadowed/(8f9e3060c4c689c937aa7d214ca25fca), 'c {elt}366/shadowed/(8f9e3060c4c689c937aa7d214ca25fca)) Base__.Either0.t) @ local) @ local -> ('b, 'p1, 'p2) {t}365/shadowed/(8f9e3060c4c689c937aa7d214ca25fca) * ('c, 'p1, 'p2) {t}365/shadowed/(8f9e3060c4c689c937aa7d214ca25fca)

partition_mapi t ~f is like partition_map. Additionally, it passes the index as an argument.

Sourceval map : ('a : value_or_null mod separable) ('b : value_or_null mod separable). 'a t -> f:('a -> 'b) @ local -> 'b t
Sourceval mapi : ('a : value_or_null mod separable) ('b : value_or_null mod separable). 'a t -> f:(int -> ('a -> 'b) @ local) @ local -> 'b t
Sourceval iteri : ('a : value_or_null mod separable). 'a t -> f:(int -> ('a -> unit) @ local) @ local -> unit
Sourceval iter : ('a : value_or_null mod separable). 'a t -> f:('a -> unit) @ local -> unit
Sourceval for_all : ('a : value_or_null mod separable). 'a t -> f:('a -> bool) @ local -> bool
Sourceval find_or_null : 'a. 'a t -> f:('a -> bool) @ local -> 'a or_null

Like find but returning or_null instead of option.

Sourceval findi_or_null : 'a. 'a t -> f:(int -> ('a -> bool) @ local) @ local -> (int * 'a) or_null

Like findi but returning or_null instead of option.

Sourceval find_map_or_null : 'a 'b. 'a t -> f:('a -> 'b or_null) @ local -> 'b or_null

Like find_map but with a function returning or_null instead of option.

Sourceval find_mapi_or_null : 'a 'b. 'a t -> f:(int -> ('a -> 'b or_null) @ local) @ local -> 'b or_null

Like find_mapi but with a function returning or_null instead of option.

Sourceval of_array : ('a : value_or_null mod separable). 'a array -> 'a t
Sourceval to_array : ('a : value_or_null mod separable). 'a t -> 'a array
include Invariant.S1 with type 'a t := 'a t
Sourceval invariant : ('a -> unit) -> 'a t -> unit

Operators

Sourcemodule O : sig ... end
Sourceval (.:()) : ('a : any mod separable). 'a Basement.Stdlib_iarray_labels.t -> int -> 'a

An alias for get.

Indexing

Sourceval length : ('a : any mod separable). 'a t @ immutable -> int
Sourceval get : ('a : any mod separable). 'a t -> int -> 'a
Sourceval get_opt : 'a t -> int -> 'a option
Sourceval unsafe_get : ('a : any mod separable). 'a t -> int -> 'a
include sig ... end
Sourceval last_exn : 'a t -> 'a

Functional update

Sourceval set : 'a t -> int -> 'a -> 'a t
Sourceval update : 'a t -> int -> f:('a -> 'a) -> 'a t

Constructors

Sourceval empty : _ t
Sourceval singleton : 'a -> 'a t
Sourceval create : len:int -> 'a -> mutate:('a array @ local -> unit) @ local -> 'a Basement.Stdlib_iarray_labels.t
Sourceval init : ('a : value_or_null mod separable). int -> f:(int -> 'a) @ local -> 'a t

Conversions

Sourceval of_sequence : 'a Sequence.t -> 'a t
Sourceval to_sequence : 'a t -> 'a Sequence.t
Sourceval of_list_rev : ('a : value_or_null mod separable). 'a list -> 'a t
Sourceval of_list_map : 'a list -> f:('a -> 'b) @ local -> 'b t
Sourceval of_list_mapi : 'a list -> f:(int -> ('a -> 'b) @ local) @ local -> 'b t
Sourceval of_list_rev_map : 'a list -> f:('a -> 'b) @ local -> 'b t

Subsequences

Sourceval prefix : 'a t -> len:int -> 'a t
Sourceval suffix : 'a t -> len:int -> 'a t
Sourceval drop_prefix : 'a t -> len:int -> 'a t
Sourceval drop_suffix : 'a t -> len:int -> 'a t
Sourceval group : 'a t -> break:('a -> ('a -> bool) @ local) @ local -> 'a t t
Sourceval split_n : 'a t -> int -> 'a t * 'a t

split_n t n returns a pair of iarrays (first, second) where first contains the first n elements of t and second contains the remaining elements.

  • If n >= length t, returns (t, empty).
  • If n <= 0, returns (empty, t).
Sourceval chunks_of : 'a t -> length:int -> 'a t t

chunks_of t ~length returns an iarray of iarrays whose concatenation is equal to the original iarray. Every iarray has length elements, except for possibly the last iarray, which may have fewer. chunks_of raises if length <= 0.

Reordering

Sourceval rev : 'a t -> 'a t
Sourceval sort : 'a t -> compare:('a -> ('a -> int) @ local) @ local -> 'a t
Sourceval stable_sort : 'b t -> compare:('b -> 'b -> int) -> 'b t
Sourceval dedup_and_sort : 'a t -> compare:('a -> ('a -> int) @ local) @ local -> 'a t
Sourceval sort_and_group : 'a t -> compare:('a -> ('a -> int) @ local) @ local -> 'a t t
Sourceval is_sorted : 'a t -> compare:('a -> ('a -> int) @ local) @ local -> bool
Sourceval is_sorted_strictly : 'a t -> compare:('a -> ('a -> int) @ local) @ local -> bool
Sourceval find_a_dup : 'a t -> compare:('a -> ('a -> int) @ local) @ local -> 'a option

Combining elements

Sourceval reduce : 'a t -> f:('a -> ('a -> 'a) @ local) @ local -> 'a option
Sourceval reduce_exn : 'a t -> f:('a -> ('a -> 'a) @ local) @ local -> 'a
Sourceval combine_errors : 'a Or_error.t t -> 'a t Or_error.t
Sourceval combine_errors_unit : unit Or_error.t t -> unit Or_error.t
Sourceval fold : ('a : value_or_null mod separable) ('acc : value_or_null). 'a t -> init:'acc -> f:('acc -> ('a -> 'acc) @ local) @ local -> 'acc
Sourceval foldi : ('a : value_or_null mod separable) ('acc : value_or_null). 'a t -> init:'acc -> f:(int -> ('acc -> ('a -> 'acc) @ local) @ local) @ local -> 'acc
Sourceval fold_right : ('a : value_or_null mod separable) ('acc : value_or_null). 'a t -> init:'acc -> f:('a -> ('acc -> 'acc) @ local) @ local -> 'acc
Sourceval fold_map : 'a t -> init:'acc -> f:('acc -> ('a -> 'acc * 'b) @ local) @ local -> 'acc * 'b t
Sourceval fold_mapi : 'a t -> init:'acc -> f:(int -> ('acc -> ('a -> 'acc * 'b) @ local) @ local) @ local -> 'acc * 'b t

Multiple arrays

Sourceval zip : 'a t -> 'b t -> ('a * 'b) t option
Sourceval zip_exn : 'a t -> 'b t -> ('a * 'b) t
Sourceval unzip : ('a * 'b) t -> 'a t * 'b t
Sourceval map2_exn : 'a t -> 'b t -> f:('a -> ('b -> 'c) @ local) @ local -> 'c t
Sourceval iter2_exn : 'a t -> 'b t -> f:('a -> ('b -> unit) @ local) @ local -> unit
Sourceval cartesian_product : 'a t -> 'b t -> ('a * 'b) t

Random elements

Sourceval random_element : ?random_state:Random.State.t -> 'a t -> 'a option
Sourceval random_element_exn : ?random_state:Random.State.t -> 'a t -> 'a

Blit operations

Sourceval sub : 'a t -> pos:int -> len:int -> 'a t
Sourceval subo : ?pos:int -> ?len:int -> 'a t -> 'a t
Sourcemodule Of_array : sig ... end
Sourcemodule To_array : sig ... end
Sourcemodule Local : sig ... end

Operations for local iarrays.

Sourcemodule Unique : sig ... end

Operations for unique iarrays

Unsafe conversions

Immutable arrays can be converted to and from mutable arrays, as they can have the same representation. One must be careful not to modify the mutable array sharing a representation with an immutable array at any time when both are reachable. Doing so violates the invariants of the immutable array. The OCaml compiler might rely on these invariants when compiling or optimizing code that uses immutable arrays.

Sourceval unsafe_to_array__promise_no_mutation : ('a : any mod separable). 'a t -> 'a array
Sourceval unsafe_of_array__promise_no_mutation : ('a : any mod separable). 'a array -> 'a t