Fork me on GitHub

I want to use filter on a persistent list to filter out a certain element and assign that to the binding that runs the filter, this works just fine. But what I would really like to do is update that same element from within the the filter. Is that possible? I've been grinding my head for the last cpl of hours but am not succeeding. Here's an example, lets say I have a binding called cases. In the example I predefine them but in my app they come from another function. I want to get out 1 case called mycase and for example print that. This works just fine. (let [cases '({:somename ({:id "2212020"}), :admin 12, :id 123, :defid "9985", :somevalue "2022-02-10T18:00:08.000Z"} {:somename ({:id "1231"}), :admin 13, :id 456, :defid "9985", :somevalue "2022-02-10T18:00:08.000Z"} {:somename ({:id "345345"}), :admin 14, :id 789, :defid "9985", :somevalue "2022-02-10T18:00:08.000Z"})       mycase (remove (fn [case] (if (= (:admin case) 13) (println "got it!") true)) cases)]   (println mycase)) Output: (got it! {:somename ({:id 1231}), :admin 13, :id 456, :defid 9985, :somevalue 2022-02-10T18:00:08.000Z}) Would it be possible to update the contents of mycase that I collect using remove while removing it? I have tried but failed.


so you would like to update mycase - you can do this either with a new map over that seq, of use a transducer while removing


(map update-fn mycase)



(into [] (comp (remove ...) (map update-fn)) cases)


update-fn? that would be the function that I define updates it right?


yes, update-fn is just a placeholder that you write


user=> (remove odd? [1 2 3 4 5])
(2 4)
user=> (map inc (remove odd? [1 2 3 4 5]))
(3 5)
user=> (into [] (comp (remove odd?) (map inc)) [1 2 3 4 5])
[3 5]


you can also use keep:

user=> (keep (fn [n] (when (not (odd? n)) (inc n))) [1 2 3 4 5])
(3 5)


cool thanks will try