Fork me on GitHub
#specter
<
2017-03-23
>
mmer21:03:00

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:

mmer21:03:42

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.

nathanmarz21:03:30

@mmer not understanding your input

nathanmarz21:03:40

it's not a map, did you mean to have a vector of maps?

nathanmarz21:03:51

what's "type" and "desc"? strings?

nathanmarz21:03:55

same with their values

nathanmarz21:03:16

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?

mmer22:03:40

Sorry I missed the key in the outside map now edited as it is

nathanmarz22:03:14

ok, I'll just assume the keys are keywords and the value for properties is a sequence

nathanmarz22:03:21

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)

nathanmarz22:03:19

with https://github.com/nathanmarz/specter/issues/183 you could do this without any custom or anonymous functions

nathanmarz22:03:12

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 "")

mmer22:03:59

Thanks once again

mmer22:03:39

I am rather puzzled by the #anglican? I presume that is slack getting in the way?

nathanmarz22:03:34

hmm not sure why it did that

mmer23:03:28

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

nathanmarz23:03:44

well, ALL on a map navigates you to a vector of [key value]

nathanmarz23:03:59

the next ALL navigates you to each key and value

nathanmarz23:03:21

then the selected? line navigates to :desc for each of those values, which in some cases is nil

nathanmarz23:03:33

so doing .contains on nil will be a NullPointedException

nathanmarz23:03:38

you probably wanted to replace :properties with MAP-VALS, but I'm not sure since your input data still isn't clear