ajuc wrote: > On 20 Lis, 01:49, nchubrich <nicholas.chubr...@gmail.com> wrote: >> While we're on the topic, where is something like (subtract [1 2 3 3 4 >> 4 5 6] evens) -> (1 3 3 5)? Doesn't seem to be in seq-utils or API. >> Seems like there should be a parallel "multiset" library for colls, to >> clojure.set. (I guess there could be two versions of subtract, one >> that removes \all, and one that removes only as many as are in the >> subtracted set.) Maybe I will write this unless there is already some >> such out there > > Did you mean remove? It's in core. > > (user=> (remove even? [1 2 3 3 4 5 6]) > (1 3 3 5)
and note that you can use a set as the predicate: (remove #{2 3 5} [1 2 3 4 5 6 7]) => (1 4 6 7) So if you wanted to "subtract" two vectors: (remove (set [2 3 5]) [1 2 3 4 5 6 7]) => (1 4 6 7) Doing it "multiset" style (removing only as many as are in the subtracted set) might require some more thought though, it might be more efficient to use a hash map representation for your multiset and then do: (merge-with - {:a 2, :b 1} {:a 1, :b 1}) => {:a 0 :b 1} That doesn't remove "zero" values though, which may or may not be a good thing depending on exactly how you want to use it. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en