Module Utils.Ext_list
val to_yojson : ('a -> Yojson.Safe.t) -> 'a t -> Yojson.Safe.tval of_yojson :
(Yojson.Safe.t -> 'a Ppx_deriving_yojson_runtime.error_or) ->
Yojson.Safe.t ->
'a t Ppx_deriving_yojson_runtime.error_orval make : unit -> 'a tval clear : 'a t -> unitval prepend : 'a -> 'a t -> unitval append : 'a -> 'a t -> unitval add : 'a -> 'a t -> unitval add_all : 'a list -> 'a t -> unitval length : 'a t -> intval to_list : 'a t -> 'a listval of_list : 'a list -> 'a tval mem : ?equal:('a -> 'a -> bool) -> 'a -> 'a t -> boolconcat dest src moves all the elements in src to dst
Elements are moved, not copied; src is left empty at the end
val map_inplace : ('a -> 'a) -> 'a t -> unitval fold_left : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'bval iter : ('a -> unit) -> 'a t -> unitUnlike List.for_all2, if the two lists given in parameters are not of the same size, it returns 0 instead of raising Invalid_argument
val exists : ('a -> bool) -> 'a t -> boolval assoc_opt : 'a -> ('a * 'b) t -> 'b optionval remove_duplicates : ?equal:('a -> 'a -> bool) -> 'a t -> unitval filter_map_stop :
('a -> [< `Replace of 'a | `Filter | `Stop ]) ->
'a t ->
boolFilter-maps the list in place according to f
For each element x:
- If
f x = `Filter, dropxfrom the list and continue - If
f x = `Replace y, replacexwithyin the list and continue - If
f x = `Stop, stop filtering, leaving the rest of the list unchanged
Returns whether `Stop was encountered
For example:
let f =
fun x ->
if x < 5 then `Filter else if x = 10 then `Stop else `Replace (x + 1)
in
filter_map_stop_cond f
[ 1; 2; 6; 7; 4 ] (* modifies the list into [7; 8] and returns false *)
filter_map_stop_cond f [ 1; 2; 6; 7; 10; 8; 4 ]
(* modifies the list into [ 7; 8; 10; 8; 4 ] and returns true *)val filter_stop_cond : keep:('a -> bool) -> cond:('a -> bool) -> 'a t -> boolSimilar filter_map_stop, except it cannot replace elements
For each element x:
- If
keep x = false, dropxfrom the list and continue - If
keep x = true && cond x = false, continue - If
keep x = true && cond x = true, stop filtering, leaving the rest of the list unchangedkeepsays if the element should be kept andcondif the filtering should stop
If an element is not kept, the stop condition is not checked
filter_stop_cond ~keep:(fun x -> x > 5) ~cond:(fun x -> x = 10) \[ 1; 2; 6; 10; 4 \]will return [ 6; 10; 4 ]
val filter : ('a -> bool) -> 'a t -> unitKeep only elements that satisfy the predicate given as first parameter
val filter_map : ('a -> 'a option) -> 'a t -> unitIf the function returns None, the element is dropped, otherwise, it is replaced by the value
val nth : int -> 'a t -> 'a optionReturns the nth element of the list in O(n). If n < 0 or n >= length, it returns None.
val pp : sep:unit Fmt.t -> 'a Fmt.t -> 'a t Fmt.tPretty printer