diff --git a/src/core/CCList.ml b/src/core/CCList.ml index 76612fee..5d926df0 100644 --- a/src/core/CCList.ml +++ b/src/core/CCList.ml @@ -849,6 +849,21 @@ module Assoc = struct (Assoc.update [1,"1"; 2,"2"] 3 \ ~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 (** {2 Zipper} *) diff --git a/src/core/CCList.mli b/src/core/CCList.mli index ee60436a..8a9afb25 100644 --- a/src/core/CCList.mli +++ b/src/core/CCList.mli @@ -294,6 +294,10 @@ module Assoc : sig and removing [k] if it returns [None], mapping [k] to [v'] if it returns [Some v'] @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 (** {2 Zipper} *)