jon.recoil.org

Module Core.Option_arraySource

This module extends Base.Option_array with bin_io.

type 'a t = 'a Base.Option_array.t
include Bin_prot.Binable.S1 with type 'a t := 'a Core.Option_array.t
val bin_shape_t : Bin_prot.Shape.t -> Bin_prot.Shape.t
include sig ... end
include sig ... end
val bin_size_t : 'a. ('a, 'a Core.Option_array.t) Bin_prot.Size.sizer1
val bin_write_t : 'a. ('a, 'a Core.Option_array.t) Bin_prot.Write.writer1
val bin_read_t : 'a. ('a, 'a Core.Option_array.t) Bin_prot.Read.reader1
val __bin_read_t__ : 'a. ('a, 'a Core.Option_array.t) Bin_prot.Read.vtag_reader1
val bin_writer_t : 'a. ('a, 'a Core.Option_array.t) Bin_prot.Type_class.S1.writer
val bin_reader_t : 'a. ('a, 'a Core.Option_array.t) Bin_prot.Type_class.S1.reader
include Sexplib0.Sexpable.S1 with type 'a t := 'a Core.Option_array.t
include module type of struct include Base.Option_array end with type 'a t := 'a Core.Option_array.t
include Sexplib0.Sexpable.S1 with type 'a t := 'a Core.Option_array.t
val t_of_sexp : 'a. (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a Core.Option_array.t
val sexp_of_t : 'a. ('a -> Sexplib0.Sexp.t) -> 'a Core.Option_array.t -> Sexplib0.Sexp.t
val t_sexp_grammar : 'a. 'a Sexplib0.Sexp_grammar.t -> 'a Core.Option_array.t Sexplib0.Sexp_grammar.t @@ portable
val empty : _ Core.Option_array.t @@ portable
val get_empty : unit -> _ Core.Option_array.t @@ portable

For obtaining uncontended access to empty from a portable function.

val create : len:int -> _ Core.Option_array.t @@ portable

Initially filled with all None

include Base.Indexed_container.Generic with type ('a, _, _) t := 'a Core.Option_array.t and type 'a elt := 'a option
include Base.Container.Generic__''value'' with type ('a, _, _) t := 'a Core.Option_array.t with type 'a elt := 'a option
include sig ... end
include sig ... end
include sig ... end
include sig ... end
include sig ... end
include Base.Container.Generic_types__''value'' with type ('a, 'b, 'c) t := 'a Core.Option_array.t with type 'a elt := 'a option

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

include sig ... end
include sig ... end
val iteri : 'a 'p1 'p2. 'a Core.Option_array.t -> f:(int -> 'a option -> unit) @ local -> unit
val existsi : 'a 'p1 'p2. 'a Core.Option_array.t -> f:(int -> 'a option -> bool) @ local -> bool
val for_alli : 'a 'p1 'p2. 'a Core.Option_array.t -> f:(int -> 'a option -> bool) @ local -> bool
val counti : 'a 'p1 'p2. 'a Core.Option_array.t -> f:(int -> 'a option -> bool) @ local -> int
include sig ... end
include sig ... end
val foldi : 'a 'p1 'p2 'acc. 'a Core.Option_array.t -> init:'acc -> f:(int -> 'acc -> 'a option -> 'acc) @ local -> 'acc
val iteri_until : 'a 'p1 'p2 'final. 'a Core.Option_array.t -> f: (int -> 'a option -> (unit, 'final) Base.Container.Continue_or_stop.t) @ local -> finish:(int -> 'final) @ local -> 'final
val find_mapi : 'a 'p1 'p2 'b. 'a Core.Option_array.t -> f:(int -> 'a option -> 'b option) @ local -> 'b option
include sig ... end
val foldi_until : 'a 'p1 'p2 'acc 'final. 'a Core.Option_array.t -> init:'acc -> f: (int -> 'acc -> 'a option -> ('acc, 'final) Base.Container.Continue_or_stop.t) @ local -> finish:(int -> 'acc -> 'final) @ local -> 'final
include sig ... end
val findi : 'a 'p1 'p2. 'a Core.Option_array.t -> f:(int -> 'a option -> bool) @ local -> (int * 'a option) option
include Base.Container.Generic with type ('a, 'b, 'c) t := 'a Core.Option_array.t and type 'a elt := 'a option
include sig ... end
include sig ... end
val is_empty : 'a 'p1 'p2. 'a Core.Option_array.t -> bool
val iter : 'a 'p1 'p2. 'a Core.Option_array.t -> f:('a option -> unit) @ local -> unit

iter must allow exceptions raised in f to escape, terminating the iteration cleanly. The same holds for all functions below taking an f.

val exists : 'a 'p1 'p2. 'a Core.Option_array.t -> f:('a option -> 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.

val for_all : 'a 'p1 'p2. 'a Core.Option_array.t -> f:('a option -> bool) @ local -> bool

Returns true if and only if the provided function evaluates to true for all elements. This is a short-circuiting operation.

val count : 'a 'p1 'p2. 'a Core.Option_array.t -> f:('a option -> bool) @ local -> int

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

val find : 'a 'p1 'p2. 'a Core.Option_array.t -> f:('a option -> bool) @ local -> 'a option option

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

val to_list : 'a 'p1 'p2. 'a Core.Option_array.t -> 'a option list
val min_elt : 'a 'p1 'p2. 'a Core.Option_array.t -> compare:('a option -> 'a option -> int) @ local -> 'a option 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.

val max_elt : 'a 'p1 'p2. 'a Core.Option_array.t -> compare:('a option -> 'a option -> int) @ local -> 'a option option
include sig ... end
val sum : 'a 'sum 'p1 'p2. (module Base__.Container_intf.Definitions.Summable__value_or_null with type t = 'sum) -> 'a Core.Option_array.t -> f:('a option -> '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.

val iter_until : 'a 'p1 'p2 'final. 'a Core.Option_array.t -> f:('a option -> (unit, 'final) Base.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.

val fold : 'a 'p1 'p2 'acc. 'a Core.Option_array.t -> init:'acc -> f:('acc -> 'a option -> 'acc) @ local -> 'acc

fold t ~init ~f returns f (... f (f (f init e1) e2) e3 ...) en, where e1..en are the elements of t.

val fold_result : 'a 'p1 'p2 'acc 'e. 'a Core.Option_array.t -> init:'acc -> f:('acc -> 'a option -> ('acc, 'e) Stdlib.result) @ local -> ('acc, 'e) Stdlib.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.

val find_map : 'a 'p1 'p2 'b. 'a Core.Option_array.t -> f:('a option -> '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
val fold_until : 'a 'p1 'p2 'acc 'final. 'a Core.Option_array.t -> init:'acc -> f: ('acc -> 'a option -> ('acc, 'final) Base.Container.Continue_or_stop.t) @ 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
include sig ... end
val mem : 'a 'p1 'p2. 'a Core.Option_array.t -> 'a option -> equal:('a option -> 'a option -> bool) @ local -> bool

Checks whether the provided element is there, using equal.

val length : _ Core.Option_array.t @ local -> int @@ portable
val init_some : int -> f:(int -> 'a) @ local -> 'a Core.Option_array.t @@ portable
val init : int -> f:(int -> 'a option) @ local -> 'a Core.Option_array.t @@ portable
val of_array : 'a option array -> 'a Core.Option_array.t @@ portable
val of_array_some : 'a array -> 'a Core.Option_array.t @@ portable
val to_array : 'a Core.Option_array.t -> 'a option Base.Array.t @@ portable
val get : 'a Core.Option_array.t -> int -> 'a option @@ portable

get t i returns the element number i of array t, raising if i is outside the range 0 to length t - 1.

val get_or_null : 'a Core.Option_array.t -> int -> 'a Basement.Or_null_shim.t @@ portable

Similar to get, but uses or_null to avoid allocation.

val get_local : 'a Core.Option_array.t @ local -> int -> 'a option @ local @@ portable

Similar to get, but allocates result in the caller's stack region instead of heap.

val get_some_exn : 'a Core.Option_array.t -> int -> 'a @@ portable

Raises if the element number i is None.

val is_none : _ Core.Option_array.t -> int -> bool @@ portable

is_none t i = Option.is_none (get t i)

val is_some : _ Core.Option_array.t -> int -> bool @@ portable

is_some t i = Option.is_some (get t i)

These can cause arbitrary behavior when used for an out-of-bounds array access.

val unsafe_get : 'a Core.Option_array.t -> int -> 'a option @@ portable
val unsafe_get_some_exn : 'a Core.Option_array.t -> int -> 'a @@ portable

unsafe_get_some_exn t i is unsafe because it does not bounds check i. It does, however check whether the value at index i is none or some, and raises if it is none.

val unsafe_get_some_assuming_some : 'a Core.Option_array.t -> int -> 'a @@ portable

unsafe_get_some_assuming_some t i is unsafe both because it does not bounds check i and because it does not check whether the value at index i is none or some, assuming that it is some.

val unsafe_is_some : _ Core.Option_array.t -> int -> bool @@ portable
val set : 'a Core.Option_array.t -> int -> 'a option -> unit @@ portable

set t i x modifies array t in place, replacing element number i with x, raising if i is outside the range 0 to length t - 1.

val set_some : 'a Core.Option_array.t -> int -> 'a -> unit @@ portable
val set_none : _ Core.Option_array.t -> int -> unit @@ portable
val swap : _ Core.Option_array.t -> int -> int -> unit @@ portable
val clear : _ Core.Option_array.t -> unit @@ portable

Replaces all the elements of the array with None.

val map : 'a Core.Option_array.t -> f:('a option -> 'b option) @ local -> 'b Core.Option_array.t @@ portable

map f [|a1; ...; an|] applies function f to a1, a2, ..., an, in order, and builds the option_array [|f a1; ...; f an|] with the results returned by f.

val map_some : 'a Core.Option_array.t -> f:('a -> 'b) @ local -> 'b Core.Option_array.t @@ portable

map_some t ~f is like map, but None elements always map to None and Some always map to Some.

Unsafe versions of set*. Can cause arbitrary behaviour when used for an out-of-bounds array access.

val unsafe_set : 'a Core.Option_array.t -> int -> 'a option -> unit @@ portable
val unsafe_set_some : 'a Core.Option_array.t -> int -> 'a -> unit @@ portable
val unsafe_set_none : _ Core.Option_array.t -> int -> unit @@ portable
include Base.Blit.S1 with type 'a t := 'a Core.Option_array.t
val blit : src:'a Core.Option_array.t @ local -> src_pos:int -> dst:'a Core.Option_array.t @ local -> dst_pos:int -> len:int -> unit
val blito : src:'a Core.Option_array.t @ local -> ?src_pos:int -> ?src_len:int -> dst:'a Core.Option_array.t @ local -> ?dst_pos:int -> unit -> unit
val unsafe_blit : src:'a Core.Option_array.t @ local -> src_pos:int -> dst:'a Core.Option_array.t @ local -> dst_pos:int -> len:int -> unit
val sub : 'a Core.Option_array.t @ local -> pos:int -> len:int -> 'a Core.Option_array.t
val subo : ?pos:int -> ?len:int -> 'a Core.Option_array.t @ local -> 'a Core.Option_array.t
val copy : 'a Core.Option_array.t -> 'a Core.Option_array.t @@ portable

Makes a (shallow) copy of the array.