Module Core.Nonempty_listSource
A 'a t represents a non-empty list, as evidenced by the fact that there is no [] variant. The sexp representation is as a regular list (i.e., the same as the Stable.V3 module below).
For operations on a locally allocated 'a t, see Local_nonempty_list. For convenience, some functions here are also ppx_template'd over local, and we hope to fully merge the two after list is localized
include module type of struct include Base.Nonempty_list end
val compare :
('a : value_or_null). (('a : value_or_null) -> ('a : value_or_null) -> int) ->
('a : value_or_null) Core.Nonempty_list.t ->
('a : value_or_null) Core.Nonempty_list.t ->
intval compare__local :
('a : value_or_null). (('a : value_or_null) @ local ->
('a : value_or_null) @ local ->
int) ->
('a : value_or_null) Core.Nonempty_list.t @ local ->
('a : value_or_null) Core.Nonempty_list.t @ local ->
intval equal :
('a : value_or_null). (('a : value_or_null) -> ('a : value_or_null) -> bool) ->
('a : value_or_null) Core.Nonempty_list.t ->
('a : value_or_null) Core.Nonempty_list.t ->
boolval equal__local :
('a : value_or_null). (('a : value_or_null) @ local ->
('a : value_or_null) @ local ->
bool) ->
('a : value_or_null) Core.Nonempty_list.t @ local ->
('a : value_or_null) Core.Nonempty_list.t @ local ->
boolval hash_fold_t :
('a : value_or_null). (Ppx_hash_lib.Std.Hash.state ->
('a : value_or_null) ->
Ppx_hash_lib.Std.Hash.state) ->
Ppx_hash_lib.Std.Hash.state ->
('a : value_or_null) Core.Nonempty_list.t ->
Ppx_hash_lib.Std.Hash.stateval globalize :
('a : value_or_null). ('a @ local -> 'a) ->
'a Core.Nonempty_list.t @ local ->
'a Core.Nonempty_list.tinclude sig ... end
include sig ... end
include Sexplib0.Sexpable.S1 with type 'a t := 'a Core.Nonempty_list.t
val t_of_sexp :
'a. (Sexplib0.Sexp.t -> 'a) ->
Sexplib0.Sexp.t ->
'a Core.Nonempty_list.tval sexp_of_t :
'a. ('a -> Sexplib0.Sexp.t) ->
'a Core.Nonempty_list.t ->
Sexplib0.Sexp.tval t_sexp_grammar :
'a. 'a Sexplib0.Sexp_grammar.t ->
'a Core.Nonempty_list.t Sexplib0.Sexp_grammar.t @@ portableinclude Base.Comparator.Derived with type 'a t := 'a Core.Nonempty_list.t
type !'cmp comparator_witness = 'cmp Base.Nonempty_list.comparator_witnessval comparator :
('a, 'cmp) Base.Comparator.T.comparator ->
('a Core.Nonempty_list.t, 'cmp Core.Nonempty_list.comparator_witness)
Base.Comparator.T.comparatorinclude Base.Container.S1 with type 'a t := 'a Core.Nonempty_list.t
include sig ... end
include sig ... end
include sig ... end
include sig ... end
include sig ... end
include sig ... end
include Base.Invariant.S1 with type 'a t := 'a Core.Nonempty_list.t
val invariant : ('a -> unit) -> 'a Core.Nonempty_list.t -> unitinclude Base.Monad.S__'value_or_null_mod_maybe_null'__local
with type ('a : value_or_null) t := 'a Core.Nonempty_list.t
val return : 'a -> 'a Core.Nonempty_list.tConvert a value to a t.
val bind :
'a Core.Nonempty_list.t ->
f:('a -> 'b Core.Nonempty_list.t) @ local ->
'b Core.Nonempty_list.tSequences computations. bind t ~f computes f v for value(s) v in t. Well-behaved monads satisfy these "laws" (where ( >>= ) is the infix bind operator):
map t ~fis equivalent tobind t ~f:(fun x -> return (f x))return x >>= fis equivalent tof xt >>= returnis equivalent tot(t >>= f) >>= gis equivalent tot >>= fun x -> f x >>= g
val join :
'a Core.Nonempty_list.t Core.Nonempty_list.t ->
'a Core.Nonempty_list.tCombines nested t into just one layer. Equivalent to bind t ~f:Fn.id.
val ignore_m : 'a Core.Nonempty_list.t -> unit Core.Nonempty_list.tIgnores contained values of t. Equivalent to map t ~f:ignore.
val all : 'a Core.Nonempty_list.t list -> 'a list Core.Nonempty_list.tCombines a list of t.
val all_unit : unit Core.Nonempty_list.t list -> unit Core.Nonempty_list.tCombines a list of t whose contents are unimportant.
val (>>=) :
'a Core.Nonempty_list.t ->
('a -> 'b Core.Nonempty_list.t) @ local ->
'b Core.Nonempty_list.tInfix bind.
val (>>|) :
'a Core.Nonempty_list.t ->
('a -> 'b) @ local ->
'b Core.Nonempty_list.tInfix map.
include Base.Indexed_container.S1 with type 'a t := 'a Core.Nonempty_list.t
include Base.Container.S1__''value'' with type 'a t := 'a Core.Nonempty_list.t
include sig ... end
include sig ... end
val is_empty : 'a 'p1 'p2. 'a Core.Nonempty_list.t -> boolval exists :
'a 'p1 'p2. 'a Core.Nonempty_list.t ->
f:('a -> 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.Nonempty_list.t ->
f:('a -> 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.Nonempty_list.t ->
f:('a -> bool) @ local ->
intReturns the number of elements for which the provided function evaluates to true.
val find :
'a 'p1 'p2. 'a Core.Nonempty_list.t ->
f:('a -> bool) @ local ->
'a optionReturns as an option the first element for which f evaluates to true.
val min_elt :
'a 'p1 'p2. 'a Core.Nonempty_list.t ->
compare:('a -> 'a -> int) @ local ->
'a 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.Nonempty_list.t ->
compare:('a -> 'a -> int) @ local ->
'a optioninclude sig ... end
val sum :
'a 'sum 'p1 'p2. (module Base__.Container_intf.Definitions.Summable__value_or_null
with type t = 'sum) ->
'a Core.Nonempty_list.t ->
f:('a -> '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.Nonempty_list.t ->
f:('a -> (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.Nonempty_list.t ->
init:'acc ->
f:('acc -> 'a -> '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.Nonempty_list.t ->
init:'acc ->
f:('acc -> 'a -> ('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.Nonempty_list.t ->
f:('a -> '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.Nonempty_list.t ->
init:'acc ->
f:('acc -> 'a -> ('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.Nonempty_list.t ->
'a ->
equal:('a -> 'a -> bool) @ local ->
boolChecks whether the provided element is there, using equal.
include sig ... end
val to_array : 'a. 'a Core.Nonempty_list.t -> 'a arrayinclude Base.Container.Generic_types__''value''
with type ('a, _, _) t := 'a Core.Nonempty_list.t
with type 'a elt := 'a
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 existsi :
'a 'p1 'p2. 'a Core.Nonempty_list.t ->
f:(int -> 'a -> bool) @ local ->
boolval for_alli :
'a 'p1 'p2. 'a Core.Nonempty_list.t ->
f:(int -> 'a -> bool) @ local ->
boolval counti :
'a 'p1 'p2. 'a Core.Nonempty_list.t ->
f:(int -> 'a -> bool) @ local ->
intinclude sig ... end
include sig ... end
val foldi :
'a 'p1 'p2 'acc. 'a Core.Nonempty_list.t ->
init:'acc ->
f:(int -> 'acc -> 'a -> 'acc) @ local ->
'accval iteri_until :
'a 'p1 'p2 'final. 'a Core.Nonempty_list.t ->
f:(int -> 'a -> (unit, 'final) Base.Container.Continue_or_stop.t) @ local ->
finish:(int -> 'final) @ local ->
'finalval find_mapi :
'a 'p1 'p2 'b. 'a Core.Nonempty_list.t ->
f:(int -> 'a -> 'b option) @ local ->
'b optioninclude sig ... end
val foldi_until :
'a 'p1 'p2 'acc 'final. 'a Core.Nonempty_list.t ->
init:'acc ->
f:
(int -> 'acc -> 'a -> ('acc, 'final) Base.Container.Continue_or_stop.t) @ local ->
finish:(int -> 'acc -> 'final) @ local ->
'finalinclude sig ... end
val findi :
'a 'p1 'p2. 'a Core.Nonempty_list.t ->
f:(int -> 'a -> bool) @ local ->
(int * 'a) optioninclude sig ... end
include sig ... end
val create :
('a : value_or_null). 'a ->
'a Base.List.t ->
'a Core.Nonempty_list.tval init :
('a : value_or_null). int ->
f:(int -> 'a) @ local ->
'a Core.Nonempty_list.tinit n ~f creates a list of length n where the element at index i is the value of f i. Raises if n < 1. f is called on indices from the highest to lowest, so the order of side effects is reversed: Nonempty_list.init 3 ~f:print_int prints
210.
val of_list :
('a : value_or_null). 'a Base.List.t ->
'a Core.Nonempty_list.t optionval of_list_or_null :
('a : value_or_null). 'a Base.List.t ->
'a Core.Nonempty_list.t Basement.Or_null_shim.tval of_list_error :
('a : value_or_null). 'a Base.List.t ->
'a Core.Nonempty_list.t Base.Or_error.tval of_list_exn :
('a : value_or_null). 'a Base.List.t ->
'a Core.Nonempty_list.tval to_list : ('a : value_or_null). 'a Core.Nonempty_list.t -> 'a Base.List.tval singleton : ('a : value_or_null). 'a -> 'a Core.Nonempty_list.tval cons :
('a : value_or_null). 'a ->
'a Core.Nonempty_list.t ->
'a Core.Nonempty_list.tval hd : ('a : value_or_null). 'a Core.Nonempty_list.t -> 'aval tl : ('a : value_or_null). 'a Core.Nonempty_list.t -> 'a Base.List.tval nth :
('a : value_or_null). 'a Core.Nonempty_list.t ->
int ->
'a Base.Option.tval nth_exn : ('a : value_or_null). 'a Core.Nonempty_list.t -> int -> 'aval reverse :
('a : value_or_null). 'a Core.Nonempty_list.t ->
'a Core.Nonempty_list.tval append :
('a : value_or_null). 'a Core.Nonempty_list.t ->
'a Base.List.t ->
'a Core.Nonempty_list.tval (@) :
('a : value_or_null). 'a Core.Nonempty_list.t ->
'a Core.Nonempty_list.t ->
'a Core.Nonempty_list.tval filter :
('a : value_or_null). 'a Core.Nonempty_list.t ->
f:('a -> bool) @ local ->
'a Base.List.tval filteri :
('a : value_or_null). 'a Core.Nonempty_list.t ->
f:(int -> 'a -> bool) @ local ->
'a Base.List.tval last : ('a : value_or_null). 'a Core.Nonempty_list.t -> 'aval iter : 'a Core.Nonempty_list.t -> f:('a -> unit) @ local -> unitval iteri : 'a Core.Nonempty_list.t -> f:(int -> 'a -> unit) @ local -> unitval length : ('a : value_or_null). 'a Core.Nonempty_list.t -> intinclude sig ... end
val map :
('a : value_or_null) ('b : value_or_null). 'a Core.Nonempty_list.t ->
f:('a -> 'b) @ local ->
'b Core.Nonempty_list.tval mapi :
('a : value_or_null) ('b : value_or_null). 'a Core.Nonempty_list.t ->
f:(int -> 'a -> 'b) @ local ->
'b Core.Nonempty_list.tval filter_map :
('a : value_or_null) ('b : value_or_null). 'a Core.Nonempty_list.t ->
f:('a -> 'b Base.Option.t) @ local ->
'b Base.List.tval filter_mapi :
('a : value_or_null) ('b : value_or_null). 'a Core.Nonempty_list.t ->
f:(int -> 'a -> 'b Base.Option.t) @ local ->
'b Base.List.tval concat_map :
('a : value_or_null) ('b : value_or_null). 'a Core.Nonempty_list.t ->
f:('a -> 'b Core.Nonempty_list.t) @ local ->
'b Core.Nonempty_list.tval reduce :
'a Core.Nonempty_list.t ->
f:('a -> 'a -> 'a) @ local ->
'a @@ portableval append' :
'a list ->
'a Core.Nonempty_list.t ->
'a Core.Nonempty_list.t @@ portableval unzip :
('a * 'b) Core.Nonempty_list.t ->
'a Core.Nonempty_list.t * 'b Core.Nonempty_list.t @@ portableval unzip3 :
('a * 'b * 'c) Core.Nonempty_list.t ->
'a Core.Nonempty_list.t * 'b Core.Nonempty_list.t * 'c Core.Nonempty_list.t @@ portableval zip :
'a Core.Nonempty_list.t ->
'b Core.Nonempty_list.t ->
('a * 'b) Core.Nonempty_list.t Base.List.Or_unequal_lengths.t @@ portableval zip_exn :
'a Core.Nonempty_list.t ->
'b Core.Nonempty_list.t ->
('a * 'b) Core.Nonempty_list.t @@ portableval zip3 :
'a Core.Nonempty_list.t ->
'b Core.Nonempty_list.t ->
'c Core.Nonempty_list.t ->
('a * 'b * 'c) Core.Nonempty_list.t Base.List.Or_unequal_lengths.t @@ portableval zip3_exn :
'a Core.Nonempty_list.t ->
'b Core.Nonempty_list.t ->
'c Core.Nonempty_list.t ->
('a * 'b * 'c) Core.Nonempty_list.t @@ portableval map2 :
'a Core.Nonempty_list.t ->
'b Core.Nonempty_list.t ->
f:('a -> 'b -> 'c) @ local ->
'c Core.Nonempty_list.t Base.List.Or_unequal_lengths.t @@ portableval map2_exn :
'a Core.Nonempty_list.t ->
'b Core.Nonempty_list.t ->
f:('a -> 'b -> 'c) @ local ->
'c Core.Nonempty_list.t @@ portableval filter_opt : 'a option Core.Nonempty_list.t -> 'a list @@ portableval concat :
'a Core.Nonempty_list.t Core.Nonempty_list.t ->
'a Core.Nonempty_list.t @@ portableval drop_last : 'a Core.Nonempty_list.t -> 'a list @@ portableval to_sequence : 'a Core.Nonempty_list.t -> 'a Base.Sequence.t @@ portableval sort :
'a Core.Nonempty_list.t ->
compare:('a -> 'a -> int) @ local ->
'a Core.Nonempty_list.t @@ portableval group :
'a Core.Nonempty_list.t ->
break:('a -> 'a -> bool) @ local ->
'a Core.Nonempty_list.t Core.Nonempty_list.t @@ portableval sort_and_group :
'a Core.Nonempty_list.t ->
compare:('a -> 'a -> int) @ local ->
'a Core.Nonempty_list.t Core.Nonempty_list.t @@ portableval stable_sort :
'a Core.Nonempty_list.t ->
compare:('a -> 'a -> int) @ local ->
'a Core.Nonempty_list.t @@ portableval stable_dedup :
'a Core.Nonempty_list.t ->
compare:('a -> 'a -> int) ->
'a Core.Nonempty_list.t @@ portableval dedup_and_sort :
'a Core.Nonempty_list.t ->
compare:('a -> 'a -> int) @ local ->
'a Core.Nonempty_list.t @@ portableval permute :
?random_state:Base.Random.State.t ->
'a Core.Nonempty_list.t ->
'a Core.Nonempty_list.t @@ portableval random_element :
?random_state:Base.Random.State.t ->
'a Core.Nonempty_list.t ->
'a @@ portableval cartesian_product :
'a Core.Nonempty_list.t ->
'b Core.Nonempty_list.t ->
('a * 'b) Core.Nonempty_list.t @@ portableval fold_nonempty :
'a Core.Nonempty_list.t ->
init:('a -> 'acc) @ local ->
f:('acc -> 'a -> 'acc) @ local ->
'acc @@ portableval fold_right :
'a Core.Nonempty_list.t ->
init:'b ->
f:('a -> 'b -> 'b) @ local ->
'b @@ portableval folding_map :
'a Core.Nonempty_list.t ->
init:'b ->
f:('b -> 'a -> 'b * 'c) @ local ->
'c Core.Nonempty_list.t @@ portableval fold_map :
'a Core.Nonempty_list.t ->
init:'acc ->
f:('acc -> 'a -> 'acc * 'b) @ local ->
'acc * 'b Core.Nonempty_list.t @@ portableval findi_exn :
'a Core.Nonempty_list.t ->
f:(int -> 'a -> bool) @ local ->
int * 'a @@ portableval all_equal :
'a Core.Nonempty_list.t ->
equal:('a -> 'a -> bool) @ local ->
'a option @@ portableall_equal returns a single element of the list that is equal to all other elements, or None if no such element exists.
val is_sorted :
'a Core.Nonempty_list.t ->
compare:('a -> 'a -> int) @ local ->
bool @@ portableis_sorted t ~compare returns true iff for all adjacent a1; a2 in t, compare a1 a2 <= 0.
val is_sorted_strictly :
'a Core.Nonempty_list.t ->
compare:('a -> 'a -> int) @ local ->
bool @@ portableis_sorted_strictly t ~compare returns true iff for all adjacent a1; a2 in t, compare a1 a2 < 0.
val min_elt' :
'a Core.Nonempty_list.t ->
compare:('a -> 'a -> int) @ local ->
'a @@ portablemin_elt' and max_elt' differ from min_elt and max_elt (included in Container.S1) in that they don't return options.
val max_elt' :
'a Core.Nonempty_list.t ->
compare:('a -> 'a -> int) @ local ->
'a @@ portableval transpose :
'a Core.Nonempty_list.t Core.Nonempty_list.t ->
'a Core.Nonempty_list.t Core.Nonempty_list.t option @@ portabletranspose takes an n x m list of lists to an m x n list of lists. Hence, if the input lists are all non-empty, the output lists will also all be non-empty.
val transpose_exn :
'a Core.Nonempty_list.t Core.Nonempty_list.t ->
'a Core.Nonempty_list.t Core.Nonempty_list.t @@ portableval map_add_multi :
('k, 'v Core.Nonempty_list.t, 'cmp) Base.Map.t ->
key:'k ->
data:'v ->
('k, 'v Core.Nonempty_list.t, 'cmp) Base.Map.t @@ portableLike Map.add_multi, but comes with a guarantee that the range of the returned map is all nonempty lists.
val hashtbl_add_multi :
('k, 'v Core.Nonempty_list.t) Base.Hashtbl.t ->
key:'k ->
data:'v ->
unit @@ portableLike Hashtbl.add_multi, but comes with a guarantee that list that's added to or created is a nonempty list.
val map_of_alist_multi :
('k * 'v) list ->
comparator:('k, 'cmp) Base.Comparator.Module.t ->
('k, 'v Core.Nonempty_list.t, 'cmp) Base.Map.t @@ portableLike Map.of_alist_multi, but comes with a guarantee that the range of the returned map is all nonempty lists.
val map_of_alist_multi_rev :
('k * 'v) list ->
comparator:('k, 'cmp) Base.Comparator.Module.t ->
('k, 'v Core.Nonempty_list.t, 'cmp) Base.Map.t @@ portableLike map_of_alist_multi but the elements in the resulting nonempty lists will be in the reverse order of the input list. Uses of this function should probably be replaced with map_of_alist_multi
val map_of_sequence_multi :
('k * 'v) Base.Sequence.t ->
comparator:('k, 'cmp) Base.Comparator.Module.t ->
('k, 'v Core.Nonempty_list.t, 'cmp) Base.Map.t @@ portableLike Map.of_sequence_multi, but comes with a guarantee that the range of the returned map is all nonempty lists.
val map_of_sequence_multi_rev :
('k * 'v) Base.Sequence.t ->
comparator:('k, 'cmp) Base.Comparator.Module.t ->
('k, 'v Core.Nonempty_list.t, 'cmp) Base.Map.t @@ portableLike map_of_sequence_multi but the elements in the resulting nonempty lists will be in the reverse order of the input sequence. Uses of this function should probably be replaced with map_of_sequence_multi
val map_of_list_with_key_multi :
'v list ->
comparator:('k, 'cmp) Base.Comparator.Module.t ->
get_key:('v -> 'k) ->
('k, 'v Core.Nonempty_list.t, 'cmp) Base.Map.t @@ portableLike Map.of_list_with_key_multi, but comes with a guarantee that the range of the returned map is all nonempty lists.
val map_of_list_with_key_multi_rev :
'v list ->
comparator:('k, 'cmp) Base.Comparator.Module.t ->
get_key:('v -> 'k) ->
('k, 'v Core.Nonempty_list.t, 'cmp) Base.Map.t @@ portableLike map_of_list_with_key_multi but the elements in the resulting nonempty lists will be in the reverse order of the input list. Uses of this function should probably be replaced with map_of_list_with_key_multi
val combine_errors :
('ok, 'err) Base.Result.t Core.Nonempty_list.t ->
('ok Core.Nonempty_list.t, 'err Core.Nonempty_list.t) Base.Result.t @@ portableLike Result.combine_errors but for non-empty lists
val combine_errors_unit :
(unit, 'err) Base.Result.t Core.Nonempty_list.t ->
(unit, 'err Core.Nonempty_list.t) Base.Result.t @@ portableLike Result.combine_errors_unit but for non-empty lists
val combine_or_errors :
'a Base.Or_error.t Core.Nonempty_list.t ->
'a Core.Nonempty_list.t Base.Or_error.t @@ portableLike Or_error.combine_errors but for non-empty lists
val combine_or_errors_unit :
unit Base.Or_error.t Core.Nonempty_list.t ->
unit Base.Or_error.t @@ portableLike Or_error.combine_errors_unit but for non-empty lists
val filter_ok_at_least_one :
'a Base.Or_error.t Core.Nonempty_list.t ->
'a Core.Nonempty_list.t Base.Or_error.t @@ portableLike Or_error.filter_ok_at_least_one but for non-empty lists.
In particular it:
- Returns a
'a t Or_error.t, statically ensuring that in theOk lcase,lis nonempty.
- Takes a
'a Or_error.t t, ensuring that in theError ecase,eis informative, rather than having been constructed from an empty list.
val option_all :
'a option Core.Nonempty_list.t ->
'a Core.Nonempty_list.t option @@ portableLike Option.all but for non-empty lists
val remove_consecutive_duplicates :
?which_to_keep:[ `First | `Last ] ->
'a Core.Nonempty_list.t ->
equal:('a -> 'a -> bool) @ local ->
'a Core.Nonempty_list.t @@ portableReturns the given t with consecutive duplicates removed. The relative order of the other elements is unaffected. The element kept from a run of duplicates is determined by which_to_keep.
val partition_tf :
'a Core.Nonempty_list.t ->
f:('a -> bool) @ local ->
('a, 'a) Partition.t @@ portablepartition_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).
At least one of the two parts must be nonempty, which is represented by the type of Partition.t.
val partition_tf' :
'a Core.Nonempty_list.t ->
f:('a -> bool) @ local ->
'a list * 'a list @@ portableLike partition_tf, but returns the parts in two lists instead.
val partition_map :
'a Core.Nonempty_list.t ->
f:('a -> ('fst, 'snd) Base.Either.t) @ local ->
('fst, 'snd) Partition.t @@ portablepartition_map t ~f partitions t according to f.
At least one of the two parts must be nonempty, which is represented by the type of Partition.t.
val partition_map' :
'a Core.Nonempty_list.t ->
f:('a -> ('fst, 'snd) Base.Either.t) @ local ->
'fst list * 'snd list @@ portableLike partition_map, but returns the parts in two lists instead.
val partition_result :
('ok, 'error) Base.Result.t Core.Nonempty_list.t ->
('ok, 'error) Partition.t @@ portablepartition_result t returns a pair t1, t2, where t1 is the all Ok elements in t and t2 is the list of all Error elements. The order of elements in the input list is preserved.
At least one of the two parts must be nonempty, which is represented by the type of Partition.t.
val partition_result' :
('ok, 'error) Base.Result.t Core.Nonempty_list.t ->
'ok list * 'error list @@ portableLike partition_result, but returns the parts in two lists instead.
val partition3_map :
'a Core.Nonempty_list.t ->
f:('a -> [ `Fst of 'fst | `Snd of 'snd | `Trd of 'trd ]) @ local ->
('fst, 'snd, 'trd) Partition3.t @@ portableinclude sig ... end
val quickcheck_generator :
'a. 'a Ppx_quickcheck_runtime.Base_quickcheck.Generator.t ->
'a Core.Nonempty_list.t Ppx_quickcheck_runtime.Base_quickcheck.Generator.t @@ portableval quickcheck_generator__portable :
'a. 'a Ppx_quickcheck_runtime.Base_quickcheck.Generator.t @ portable ->
'a Core.Nonempty_list.t Ppx_quickcheck_runtime.Base_quickcheck.Generator.t @ portable @@ portableval quickcheck_observer :
'a. 'a Ppx_quickcheck_runtime.Base_quickcheck.Observer.t ->
'a Core.Nonempty_list.t Ppx_quickcheck_runtime.Base_quickcheck.Observer.t @@ portableval quickcheck_observer__portable :
'a. 'a Ppx_quickcheck_runtime.Base_quickcheck.Observer.t @ portable ->
'a Core.Nonempty_list.t Ppx_quickcheck_runtime.Base_quickcheck.Observer.t @ portable @@ portableval quickcheck_shrinker :
'a. 'a Ppx_quickcheck_runtime.Base_quickcheck.Shrinker.t ->
'a Core.Nonempty_list.t Ppx_quickcheck_runtime.Base_quickcheck.Shrinker.t @@ portableval quickcheck_shrinker__portable :
'a. 'a Ppx_quickcheck_runtime.Base_quickcheck.Shrinker.t @ portable ->
'a Core.Nonempty_list.t Ppx_quickcheck_runtime.Base_quickcheck.Shrinker.t @ portable @@ portableinclude Typerep_lib.Typerepable.S1 with type 'a t := 'a Core.Nonempty_list.t
val typerep_of_t :
'a Typerep_lib.Std_internal.Typerep.t ->
'a Core.Nonempty_list.t Typerep_lib.Std_internal.Typerep.t @@ portableval typename_of_t :
'a Typerep_lib.Typename.t ->
'a Core.Nonempty_list.t Typerep_lib.Typename.t @@ portabletype 'a nonempty_list := 'a Core.Nonempty_list.tval validate_indexed :
'a Validate.check ->
'a Core.Nonempty_list.t Validate.check @@ portablevalidates a list, naming each element by its position in the list (where the first position is 1, not 0).
val validate :
name:('a -> string) ->
'a Validate.check ->
'a Core.Nonempty_list.t Validate.check @@ portablevalidates a list, naming each element using a user-defined function for computing the name.
Returns a flag that must be passed one or more times. See Command.Param.one_or_more_as_pair.
val comma_separated_argtype :
?key:'a Core.Nonempty_list.t Univ_map.Multi.Key.t ->
?strip_whitespace:bool ->
?unique_values:bool ->
'a Command.Param.Arg_type.t ->
'a Core.Nonempty_list.t Command.Param.Arg_type.tAccepts comma-separated lists of arguments parsed by t. See Command.Param.Arg_type.comma_separated.
Requires one or more of an anonymous argument.
This module provides 0-alloc versions of to_list and of_list, via some and allowing you to match%optional on a list, respectively.