mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-08 12:15:32 -05:00
add CCList.Assoc.remove
This commit is contained in:
parent
8094a31604
commit
d6487a02a0
2 changed files with 19 additions and 0 deletions
|
|
@ -849,6 +849,21 @@ module Assoc = struct
|
||||||
(Assoc.update [1,"1"; 2,"2"] 3 \
|
(Assoc.update [1,"1"; 2,"2"] 3 \
|
||||||
~f:(function None -> Some "3" | _ -> assert false) |> lsort)
|
~f:(function None -> Some "3" | _ -> assert false) |> lsort)
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
let remove ?(eq=(=)) l x =
|
||||||
|
search_set eq [] l x
|
||||||
|
~f:(fun _ opt_y rest -> match opt_y with
|
||||||
|
| None -> l (* keep as is *)
|
||||||
|
| Some _ -> rest)
|
||||||
|
|
||||||
|
(*$=
|
||||||
|
[1,"1"] \
|
||||||
|
(Assoc.remove [1,"1"; 2,"2"] 2 |> lsort)
|
||||||
|
[1,"1"; 3,"3"] \
|
||||||
|
(Assoc.remove [1,"1"; 2,"2"; 3,"3"] 2 |> lsort)
|
||||||
|
[1,"1"; 2,"2"] \
|
||||||
|
(Assoc.remove [1,"1"; 2,"2"] 3 |> lsort)
|
||||||
|
*)
|
||||||
end
|
end
|
||||||
|
|
||||||
(** {2 Zipper} *)
|
(** {2 Zipper} *)
|
||||||
|
|
|
||||||
|
|
@ -294,6 +294,10 @@ module Assoc : sig
|
||||||
and removing [k] if it returns [None], mapping [k] to [v'] if it
|
and removing [k] if it returns [None], mapping [k] to [v'] if it
|
||||||
returns [Some v']
|
returns [Some v']
|
||||||
@since 0.16 *)
|
@since 0.16 *)
|
||||||
|
|
||||||
|
val remove : ?eq:('a->'a->bool) -> ('a,'b) t -> 'a -> ('a,'b) t
|
||||||
|
(** [remove l k] removes the first occurrence of [k] from [l].
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
end
|
end
|
||||||
|
|
||||||
(** {2 Zipper} *)
|
(** {2 Zipper} *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue