This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-10
Channels
- # announcements (6)
- # architecture (2)
- # babashka (30)
- # beginners (90)
- # calva (21)
- # cider (22)
- # clj-kondo (27)
- # cljs-dev (7)
- # clojure (132)
- # clojure-europe (51)
- # clojure-nl (12)
- # clojure-norway (3)
- # clojure-spec (3)
- # clojure-uk (5)
- # clojurescript (69)
- # cloverage (9)
- # conjure (5)
- # core-async (54)
- # cursive (14)
- # datomic (34)
- # emacs (7)
- # fulcro (10)
- # graalvm (40)
- # graalvm-mobile (2)
- # gratitude (2)
- # improve-getting-started (1)
- # introduce-yourself (1)
- # jobs-discuss (61)
- # leiningen (5)
- # malli (6)
- # off-topic (59)
- # pathom (11)
- # polylith (38)
- # reagent (3)
- # reitit (3)
- # rewrite-clj (3)
- # shadow-cljs (53)
- # tools-build (35)
- # transit (8)
- # vim (62)
- # web-security (26)
- # xtdb (4)
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
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]