mardi 10 mars 2015

Clojure: search/replace values in a dynamic nested map/seq


Vote count:

0




I have a dynamically created map data structure which will later on be parsed into JSON. Therefore the nesting levels, etc. are unknown and depend on the data.


If a key has multiple values, they are represented as maps inside a sequence.


Here is an example:



{:key "value"
:anotherKey "anotherValue"
:foo "test"
:others [ {:foo "test2"} {:foo "test3"} ]
:deeper {:nesting {:foo "test4"} }
}


I now want to search for the key :foo and append "bar" to the value.


What would be a clean and simple way to achieve that?


I tried a recursive approach but beside the memory problem of large data structures I'm struggling with returning my appended values.



asked 31 secs ago

echox

2,573






Clojure: search/replace values in a dynamic nested map/seq

Aucun commentaire:

Enregistrer un commentaire