mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
feat(CCList): make mem compatible with the Stdlib
The eq argument is now optional.
This commit is contained in:
parent
0f9e51fbe3
commit
2025a62536
3 changed files with 13 additions and 8 deletions
|
|
@ -1215,12 +1215,17 @@ let group_join_by (type a) ?(eq=Stdlib.(=)) ?(hash=Hashtbl.hash) f c1 c2 =
|
|||
(Error "e2") (all_ok [Ok 1; Error "e2"; Error "e3"; Ok 4])
|
||||
*)
|
||||
|
||||
let mem ~eq x l =
|
||||
let mem ?(eq=Stdlib.(=)) x l =
|
||||
let rec search eq x l = match l with
|
||||
| [] -> false
|
||||
| y::l' -> eq x y || search eq x l'
|
||||
in search eq x l
|
||||
|
||||
(*$Q mem
|
||||
Q.(small_list small_int) (fun l -> \
|
||||
mem 1 l = (List.mem 1 l))
|
||||
*)
|
||||
|
||||
let add_nodup ~eq x l =
|
||||
if mem ~eq x l then l else x::l
|
||||
|
||||
|
|
@ -1545,7 +1550,7 @@ module Assoc = struct
|
|||
= [1, "1"; 2, "2"; 3, "3"]
|
||||
*)
|
||||
|
||||
let mem ~eq x l =
|
||||
let mem ?(eq=Stdlib.(=)) x l =
|
||||
try ignore (search_exn eq l x); true
|
||||
with Not_found -> false
|
||||
|
||||
|
|
|
|||
|
|
@ -544,7 +544,7 @@ val remove_one : eq:('a -> 'a -> bool) -> 'a -> 'a t -> 'a t
|
|||
(** [remove_one x set] removes one occurrence of [x] from [set]. Linear time.
|
||||
@since 0.11 *)
|
||||
|
||||
val mem : eq:('a -> 'a -> bool) -> 'a -> 'a t -> bool
|
||||
val mem : ?eq:('a -> 'a -> bool) -> 'a -> 'a t -> bool
|
||||
(** Membership to the list. Linear time. *)
|
||||
|
||||
val subset : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> bool
|
||||
|
|
@ -607,7 +607,7 @@ module Assoc : sig
|
|||
val set : eq:('a->'a->bool) -> 'a -> 'b -> ('a,'b) t -> ('a,'b) t
|
||||
(** Add the binding into the list (erase it if already present). *)
|
||||
|
||||
val mem : eq:('a->'a->bool) -> 'a -> ('a,_) t -> bool
|
||||
val mem : ?eq:('a->'a->bool) -> 'a -> ('a,_) t -> bool
|
||||
(** [mem x l] returns [true] iff [x] is a key in [l].
|
||||
@since 0.16 *)
|
||||
|
||||
|
|
@ -637,7 +637,7 @@ val assq_opt : 'a -> ('a * 'b) t -> 'b option
|
|||
@since 1.5, but only
|
||||
@since 2.0 with labels *)
|
||||
|
||||
val mem_assoc : eq:('a -> 'a -> bool) -> 'a -> ('a * _) t -> bool
|
||||
val mem_assoc : ?eq:('a -> 'a -> bool) -> 'a -> ('a * _) t -> bool
|
||||
(** Like [Assoc.mem].
|
||||
@since 2.0 *)
|
||||
|
||||
|
|
|
|||
|
|
@ -548,7 +548,7 @@ val remove_one : eq:(('a -> 'a -> bool) [@keep_label]) -> 'a -> 'a t -> 'a t
|
|||
(** [remove_one x set] removes one occurrence of [x] from [set]. Linear time.
|
||||
@since 0.11 *)
|
||||
|
||||
val mem : eq:(('a -> 'a -> bool) [@keep_label]) -> 'a -> 'a t -> bool
|
||||
val mem : ?eq:(('a -> 'a -> bool) [@keep_label]) -> 'a -> 'a t -> bool
|
||||
(** Membership to the list. Linear time. *)
|
||||
|
||||
val subset : eq:(('a -> 'a -> bool) [@keep_label]) -> 'a t -> 'a t -> bool
|
||||
|
|
@ -611,7 +611,7 @@ module Assoc : sig
|
|||
val set : eq:(('a->'a->bool) [@keep_label]) -> 'a -> 'b -> ('a,'b) t -> ('a,'b) t
|
||||
(** Add the binding into the list (erase it if already present). *)
|
||||
|
||||
val mem : eq:(('a->'a->bool) [@keep_label]) -> 'a -> ('a,_) t -> bool
|
||||
val mem : ?eq:(('a->'a->bool) [@keep_label]) -> 'a -> ('a,_) t -> bool
|
||||
(** [mem x l] returns [true] iff [x] is a key in [l].
|
||||
@since 0.16 *)
|
||||
|
||||
|
|
@ -641,7 +641,7 @@ val assq_opt : 'a -> ('a * 'b) t -> 'b option
|
|||
@since 1.5, but only
|
||||
@since 2.0 with labels *)
|
||||
|
||||
val mem_assoc : eq:(('a -> 'a -> bool) [@keep_label]) -> 'a -> ('a * _) t -> bool
|
||||
val mem_assoc : ?eq:(('a -> 'a -> bool) [@keep_label]) -> 'a -> ('a * _) t -> bool
|
||||
(** Like [Assoc.mem].
|
||||
@since 2.0 *)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue