This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-08
Channels
- # bangalore-clj (5)
- # beginners (6)
- # boot (66)
- # cider (48)
- # cljsrn (14)
- # clojure (699)
- # clojure-austin (2)
- # clojure-berlin (1)
- # clojure-boston (5)
- # clojure-dev (3)
- # clojure-india (7)
- # clojure-italy (24)
- # clojure-nl (5)
- # clojure-russia (33)
- # clojure-spec (30)
- # clojure-uk (64)
- # clojure-ukraine (22)
- # clojurescript (123)
- # clojurewest (1)
- # cursive (18)
- # datascript (44)
- # datomic (12)
- # dirac (46)
- # figwheel (1)
- # gsoc (5)
- # hoplon (6)
- # immutant (29)
- # instaparse (1)
- # juxt (26)
- # lein-figwheel (5)
- # leiningen (4)
- # luminus (8)
- # mount (56)
- # off-topic (60)
- # om (67)
- # om-next (1)
- # onyx (8)
- # proton (28)
- # re-frame (125)
- # ring (3)
- # ring-swagger (3)
- # specter (22)
- # testing (2)
- # unrepl (1)
- # untangled (91)
how do I remove all keys where the value is ”_"
from a hash like this?
{:dim1 "slice1", :dim2 "slice2", :dim3 “_”}
I’ve tried various incantations of selected?
, subselect
and filterer
, and I can’t figure out what goes where
boot.user=> (setval [MAP-VALS #(= % "_")] NONE data)
{:dim1 "slice1", :dim2 "slice2"}
feel like cheating to use setval, I’m so used to immutability that anything involving “set” makes me nervous 😄
boot.user=> (select [ALL #(-> % val (not= "_"))] data)
[[:dim1 "slice1"] [:dim2 "slice2"]]
but this is not the right solution, since it does not return you a map + this would likely be better solved with creating a separate navigator.. which I did not wrap my head around yetindeed, but sometimes you want filter
and sometimes you want remove
, so I hope there is something equivalent in Specter 🙂
I know, and the setval
approach works just fine, but aesthetically having both filter
and remove
can make the code read nicer
which is why I want to use specter at all in this case, otherwise I’d just do (into {} (remove #(= "_" (val %)) data))
I’m hunting for use-cases in my own code where Specter makes sense, that’s why I’m trying to shoehorn it a bit in this case
@schmee keep in mind that the setval
approach will maintain the type of map and also be significantly faster than the (into {} ...)
approach