Description
If there is a better forum for this question please let me know. Also I'm relatively new to Clojure, so apologies in advance.
Minimal example yaml file (the actual files I'm dealing with are larger):
apiVersion: v1
clusters:
- cluster:
server: http://myserver
name: myname
when parsed gives back:
user=> (yaml/parse-string (slurp (io/file "/tmp/example.yaml")) :load-all)
#ordered/map ([:apiVersion "v1"] [:clusters (#ordered/map ([:cluster nil] [:server "http://myserver"] [:name "myname"]))])
I'd like to get a copy of that map with the cluster name changed from my "myname" to "myname2". But...
The type of clusters is a lazy seq
user=> (type (:clusters (yaml/parse-string (slurp (io/file "/tmp/example.yaml")) :load-all)))
clojure.lang.LazySeq
This seems to prevent using assoc-in or update-in, as a lazy seq isn't an an associative data structure. I can obviously navigate into to data structure threading it through a series of keyword and calls like first
. But then I end up returning just the inner most map and not the full file.
I feel like what I want to do can't be uncommon, so I must be missing something. Can you give me some guidance?