Module Core.Option_arraySource
This module extends Base.Option_array with bin_io.
type 'a t = 'a Base.Option_array.tinclude Bin_prot.Binable.S1 with type 'a t := 'a Core.Option_array.t
val bin_shape_t : Bin_prot.Shape.t -> Bin_prot.Shape.tinclude sig ... end
include sig ... end
val bin_size_t : 'a. ('a, 'a Core.Option_array.t) Bin_prot.Size.sizer1val bin_write_t : 'a. ('a, 'a Core.Option_array.t) Bin_prot.Write.writer1val bin_read_t : 'a. ('a, 'a Core.Option_array.t) Bin_prot.Read.reader1val __bin_read_t__ :
'a. ('a, 'a Core.Option_array.t) Bin_prot.Read.vtag_reader1val bin_writer_t :
'a. ('a, 'a Core.Option_array.t) Bin_prot.Type_class.S1.writerval bin_reader_t :
'a. ('a, 'a Core.Option_array.t) Bin_prot.Type_class.S1.readerval bin_t : 'a. ('a, 'a Core.Option_array.t) Bin_prot.Type_class.S1.tinclude Ppx_quickcheck_runtime.Quickcheckable.S1
with type 'a t := 'a Core.Option_array.t
val quickcheck_generator :
'a Base_quickcheck.Generator.t ->
'a Core.Option_array.t Base_quickcheck.Generator.tval quickcheck_observer :
'a Base_quickcheck.Observer.t ->
'a Core.Option_array.t Base_quickcheck.Observer.tval quickcheck_shrinker :
'a Base_quickcheck.Shrinker.t ->
'a Core.Option_array.t Base_quickcheck.Shrinker.tinclude 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.tval sexp_of_t :
'a. ('a -> Sexplib0.Sexp.t) ->
'a Core.Option_array.t ->
Sexplib0.Sexp.tval t_sexp_grammar :
'a. 'a Sexplib0.Sexp_grammar.t ->
'a Core.Option_array.t Sexplib0.Sexp_grammar.t @@ portableval empty : _ Core.Option_array.t @@ portableval get_empty : unit -> _ Core.Option_array.t @@ portableFor obtaining uncontended access to empty from a portable function.
val create : len:int -> _ Core.Option_array.t @@ portableInitially 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 ->
unitval existsi :
'a 'p1 'p2. 'a Core.Option_array.t ->
f:(int -> 'a option -> bool) @ local ->
boolval for_alli :
'a 'p1 'p2. 'a Core.Option_array.t ->
f:(int -> 'a option -> bool) @ local ->
boolval counti :
'a 'p1 'p2. 'a Core.Option_array.t ->
f:(int -> 'a option -> bool) @ local ->
intinclude 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 ->
'accval 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 ->
'finalval find_mapi :
'a 'p1 'p2 'b. 'a Core.Option_array.t ->
f:(int -> 'a option -> 'b option) @ local ->
'b optioninclude 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 ->
'finalinclude sig ... end
val findi :
'a 'p1 'p2. 'a Core.Option_array.t ->
f:(int -> 'a option -> bool) @ local ->
(int * 'a option) optioninclude 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 -> boolval iter :
'a 'p1 'p2. 'a Core.Option_array.t ->
f:('a option -> unit) @ local ->
unititer 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 ->
boolReturns 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 ->
boolReturns 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 ->
intReturns 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 optionReturns 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 listval min_elt :
'a 'p1 'p2. 'a Core.Option_array.t ->
compare:('a option -> 'a option -> int) @ local ->
'a option optionReturns 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 optioninclude 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 ->
'sumReturns 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 ->
'finaliter_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 ->
'accfold 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.resultfold_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 optionReturns 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 ->
'finalfold_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 -3include sig ... end
val mem :
'a 'p1 'p2. 'a Core.Option_array.t ->
'a option ->
equal:('a option -> 'a option -> bool) @ local ->
boolChecks whether the provided element is there, using equal.
val length : _ Core.Option_array.t @ local -> int @@ portableval init_some :
int ->
f:(int -> 'a) @ local ->
'a Core.Option_array.t @@ portableval init :
int ->
f:(int -> 'a option) @ local ->
'a Core.Option_array.t @@ portableval of_array : 'a option array -> 'a Core.Option_array.t @@ portableval of_array_some : 'a array -> 'a Core.Option_array.t @@ portableval to_array : 'a Core.Option_array.t -> 'a option Base.Array.t @@ portableval get : 'a Core.Option_array.t -> int -> 'a option @@ portableget 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 @@ portableSimilar to get, but uses or_null to avoid allocation.
val get_local :
'a Core.Option_array.t @ local ->
int ->
'a option @ local @@ portableSimilar 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 @@ portableRaises if the element number i is None.
val is_none : _ Core.Option_array.t -> int -> bool @@ portableis_none t i = Option.is_none (get t i)
val is_some : _ Core.Option_array.t -> int -> bool @@ portableis_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 @@ portableval unsafe_get_some_exn : 'a Core.Option_array.t -> int -> 'a @@ portableunsafe_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 @@ portableunsafe_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 @@ portableval set : 'a Core.Option_array.t -> int -> 'a option -> unit @@ portableset 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 @@ portableval set_none : _ Core.Option_array.t -> int -> unit @@ portableval swap : _ Core.Option_array.t -> int -> int -> unit @@ portableval clear : _ Core.Option_array.t -> unit @@ portableReplaces 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 @@ portablemap 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 @@ portablemap_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 @@ portableval unsafe_set_some : 'a Core.Option_array.t -> int -> 'a -> unit @@ portableval unsafe_set_none : _ Core.Option_array.t -> int -> unit @@ portableinclude 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 ->
unitval 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 ->
unitval unsafe_blit :
src:'a Core.Option_array.t @ local ->
src_pos:int ->
dst:'a Core.Option_array.t @ local ->
dst_pos:int ->
len:int ->
unitval sub :
'a Core.Option_array.t @ local ->
pos:int ->
len:int ->
'a Core.Option_array.tval subo :
?pos:int ->
?len:int ->
'a Core.Option_array.t @ local ->
'a Core.Option_array.tval copy : 'a Core.Option_array.t -> 'a Core.Option_array.t @@ portableMakes a (shallow) copy of the array.