Closed zerg000000 closed 1 year ago
@zerg000000 I think it's usually best to take a few examples into account so we can see how it should work.
For example, I want to append :create-friends-table
to the end of vector
{:migrations [:init-db
:create-user-table
:create-role-tables]}
In rewrite-edn, can i do something like?
(require '[rewrite-clj.zip :as z])
(-> (r/parse-string edn-string)
(r/update :migrations (fn [vals] (z/append-child vals :create-friends-table)))
or
(-> (r/parse-string edn-string)
(r/update :migrations (fn [vals] (r/append-child vals :create-friends-table)))
@zerg000000 Ah yes, this works:
user=> (def nodes (r/parse-string "{:a [1 2 3]}"))
#'user/nodes
user=> (str (r/update nodes :a (fn [vals] (z/root (z/append-child (z/edn vals) 4)))))
"{:a [1 2 3 4]}"
That's nice. I can live with this, any plan make this ops as part of rewrite-edn api?
I guess we could introduce conj
but this would raise the expectation that it would work for list, vector, maps and sets and behave differently for each. The most frequent use case would be vector probably.
Yeah, let's do conj
.
It might take me a while to add so if someone is willing to do a PR, welcome.
When we dealing with edn, we will always encounter updating list/vector. It would be good to have some ops for that.
Since
conj
is not always worked as expected. Don't know what would be the best to add to the api.