This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-29
Channels
- # admin-announcements (2)
- # beginners (20)
- # boot (139)
- # cider (6)
- # clara (1)
- # cljs-dev (7)
- # cljsrn (4)
- # clojure (160)
- # clojure-berlin (1)
- # clojure-canada (6)
- # clojure-gamedev (1)
- # clojure-japan (7)
- # clojure-russia (14)
- # clojure-spec (90)
- # clojure-uk (10)
- # clojurescript (73)
- # clojutre (1)
- # conf-proposals (8)
- # crypto (67)
- # cursive (9)
- # datomic (6)
- # editors-rus (1)
- # events (1)
- # figwheel (6)
- # funcool (2)
- # hoplon (19)
- # instaparse (37)
- # kekkonen (4)
- # lein-figwheel (2)
- # leiningen (5)
- # luminus (1)
- # off-topic (1)
- # om (10)
- # onyx (60)
- # protorepl (2)
- # re-frame (81)
- # reagent (10)
- # ring-swagger (15)
- # rum (6)
- # specter (17)
- # test-check (10)
- # uncomplicate (31)
- # untangled (12)
- # yada (6)
I can (dissoc {:id 1} :id)
.
Is there an idomatic way to dissoc in specter, or should I nav to the map of interest and call my own function that calls dissoc
?
@bill: you could do (view #(dissoc % :k))
, but if you use that with transform
, the key will not be added back during reconstruction
you could also write your own navigator, which would be straightforward
thanks @codonnell. I don’t understand your caveat “the key will not be added back during reconstruction”. maybe I’m not being clear: I want the key (and value) removed from the hash.
@bill: For example, (transform [(view #(dissoc % :a)) MAP-VALS] inc {:a 0 :b 0 :c 0})
gives {:b 1, :c 1}
, not {:a 0, :b 1, :c 1}
If you wrote your own navigator, you could make it have the latter behavior.
@bill: There are lots of examples on the wiki, including an example of a custom navigator at https://github.com/nathanmarz/specter/wiki/List-of-Macros#defnav
good luck!
so I here is me, removing the :id
s:
(transform [:results ALL (view #(dissoc % :id)) MAP-VALS] identity {:foo 3 :results [{:id 0 :b 0 :c 0}]})
=> {:foo 3, :results [{:b 0, :c 0}]}
It works, but it seems like calling identity
is a sign of wrongness here.@bill: I'm not at a repl, but I think you could do (transform [:results ALL] #(dissoc % :id) data)
@bill I've used a function like this in the past:
(defn dissocer [k]
(fn [m]
(dissoc m k)))
then you can do (transform [:results ALL] (dissocer :a) data)
nice ‘un @nathanmarz