This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-23
Channels
- # beginners (63)
- # cljs-dev (1)
- # cljsjs (1)
- # cljsrn (11)
- # clojure (208)
- # clojure-berlin (2)
- # clojure-dusseldorf (5)
- # clojure-italy (5)
- # clojure-norway (56)
- # clojure-russia (7)
- # clojure-spec (85)
- # clojure-uk (27)
- # clojurescript (191)
- # core-async (73)
- # cursive (4)
- # datomic (62)
- # defnpodcast (1)
- # hoplon (2)
- # jobs-rus (1)
- # juxt (14)
- # keechma (1)
- # leiningen (1)
- # lumo (126)
- # off-topic (2)
- # om (11)
- # onyx (27)
- # pedestal (52)
- # planck (21)
- # powderkeg (1)
- # re-frame (32)
- # reagent (14)
- # ring-swagger (1)
- # rum (3)
- # slack-help (19)
- # specter (23)
- # untangled (32)
- # vim (7)
- # yada (43)
Hi I have an question about adding a entry to a map based on the existence of a string within a value of a particular entry in the map:
I want to do a transform that removes the (read-only) from the desc fields and adds a map entry read-only: true to the map that contains the desc. I tried using the walker and predicate to find the entries with the (read-only) string the problem I have is that I can't find a way to create a transform that adds the entry. Removing the string is a bonus and I would be happy just to do the add.
@mmer not understanding your input
it's not a map, did you mean to have a vector of maps?
what's "type" and "desc"? strings?
same with their values
you want to convert maps containing a description containing "(read-only)"
to one with key/value pair of :read-only true
and with the ("read-only")
removed?
ok, I'll just assume the keys are keywords and the value for properties is a sequence
it would look something like:
(multi-transform [:properties
ALL
(selected? :desc #(.contains % "(read-only")))
(multi-path [:desc (terminal remove-read-only-str)]
[:read-only (terminal-val true)])]
data)
with https://github.com/nathanmarz/specter/issues/183 you could do this without any custom or anonymous functions
by replacing the anonymous function with (regex-all #"(read-only)")
and replacing remove-read-only-str
custom function with (regex-all #"(read-only)") (terminal-val "")
hmm not sure why it did that
fixed it
Thanks I do have a followup question - if you change :properties with ALL I get a NullPointerException - in fact any changes to the :properties ALL seems to result in the same exception
well, ALL
on a map navigates you to a vector of [key value]
the next ALL
navigates you to each key
and value
then the selected?
line navigates to :desc
for each of those values, which in some cases is nil
so doing .contains
on nil will be a NullPointedException
you probably wanted to replace :properties
with MAP-VALS
, but I'm not sure since your input data still isn't clear