Module Base.Option_arraySource
'a Option_array.t is a compact representation of 'a option array: it avoids allocating heap objects representing Some x, usually representing them with x instead. It uses a special representation for None that's guaranteed to never collide with any representation of Some x.
val t_sexp_grammar :
'a. 'a Sexplib0.Sexp_grammar.t ->
'a Base.Option_array.t Sexplib0.Sexp_grammar.t @@ portableFor obtaining uncontended access to empty from a portable function.
Initially filled with all None
include Base.Indexed_container.Generic
with type ('a, _, _) t := 'a Base.Option_array.t
and type 'a elt := 'a option
include Base.Container.Generic__''value''
with type ('a, _, _) t := 'a Base.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 Base.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 Base.Option_array.t ->
f:(int -> 'a option -> unit) @ local ->
unitval existsi :
'a 'p1 'p2. 'a Base.Option_array.t ->
f:(int -> 'a option -> bool) @ local ->
boolval for_alli :
'a 'p1 'p2. 'a Base.Option_array.t ->
f:(int -> 'a option -> bool) @ local ->
boolval counti :
'a 'p1 'p2. 'a Base.Option_array.t ->
f:(int -> 'a option -> bool) @ local ->
intinclude sig ... end
include sig ... end
val foldi :
'a 'p1 'p2 'acc. 'a Base.Option_array.t ->
init:'acc ->
f:(int -> 'acc -> 'a option -> 'acc) @ local ->
'accval iteri_until :
'a 'p1 'p2 'final. 'a Base.Option_array.t ->
f:(int -> 'a option -> (unit, 'final) Container.Continue_or_stop.t) @ local ->
finish:(int -> 'final) @ local ->
'finalval find_mapi :
'a 'p1 'p2 'b. 'a Base.Option_array.t ->
f:(int -> 'a option -> 'b option) @ local ->
'b optioninclude sig ... end
val foldi_until :
'a 'p1 'p2 'acc 'final. 'a Base.Option_array.t ->
init:'acc ->
f:
(int -> 'acc -> 'a option -> ('acc, 'final) Container.Continue_or_stop.t) @ local ->
finish:(int -> 'acc -> 'final) @ local ->
'finalinclude sig ... end
val findi :
'a 'p1 'p2. 'a Base.Option_array.t ->
f:(int -> 'a option -> bool) @ local ->
(int * 'a option) optioninclude Base.Container.Generic
with type ('a, 'b, 'c) t := 'a Base.Option_array.t
and type 'a elt := 'a option
include sig ... end
include sig ... end
val is_empty : 'a 'p1 'p2. 'a Base.Option_array.t -> boolval iter :
'a 'p1 'p2. 'a Base.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 Base.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 Base.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 Base.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 Base.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 Base.Option_array.t -> 'a option listval min_elt :
'a 'p1 'p2. 'a Base.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 Base.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 Base.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 Base.Option_array.t ->
f:('a option -> (unit, 'final) 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 Base.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 Base.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 Base.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 Base.Option_array.t ->
init:'acc ->
f:('acc -> 'a option -> ('acc, 'final) 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 Base.Option_array.t ->
'a option ->
equal:('a option -> 'a option -> bool) @ local ->
boolChecks whether the provided element is there, using equal.
get t i returns the element number i of array t, raising if i is outside the range 0 to length t - 1.
Similar to get, but uses or_null to avoid allocation.
Similar to get, but allocates result in the caller's stack region instead of heap.
Raises if the element number i is None.
is_none t i = Option.is_none (get t i)
is_some t i = Option.is_some (get t i)
These can cause arbitrary behavior when used for an out-of-bounds array access.
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.
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.
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.
Replaces all the elements of the array with None.
val map :
'a Base.Option_array.t ->
f:('a option -> 'b option) @ local ->
'b Base.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 Base.Option_array.t ->
f:('a -> 'b) @ local ->
'b Base.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.
include Base.Blit.S1 with type 'a t := 'a Base.Option_array.t
val blit :
src:'a Base.Option_array.t @ local ->
src_pos:int ->
dst:'a Base.Option_array.t @ local ->
dst_pos:int ->
len:int ->
unitval blito :
src:'a Base.Option_array.t @ local ->
?src_pos:int ->
?src_len:int ->
dst:'a Base.Option_array.t @ local ->
?dst_pos:int ->
unit ->
unitval unsafe_blit :
src:'a Base.Option_array.t @ local ->
src_pos:int ->
dst:'a Base.Option_array.t @ local ->
dst_pos:int ->
len:int ->
unitMakes a (shallow) copy of the array.