I'd like to rewrite a subset of a map while maintaining any part of the map not subject to the rewrite. A simple example:
{:a "a", :b "b", :c "c"} => {:a "A", :"b", :c "c"}
The only key that I care about is :a
so I'd like to just treat any remaining entries in a generic fashion. I'm having trouble finding the right meander magic.
the closest I've come is
(m/find {:a "a"
:b "b"
:c "c"}
(m/and
{:a ?a}
(m/seqable !kvs ...))
[{:a (.toUpperCase ?a)} !kvs])
Which gets me kind of close but I can't help but think there's a better approachIs there an operator similar to cond
which only matches on the first matching expression?
(m/rewrite the-map
{:a (m/pred string? ?a) & ?the-rest}
{:a (m/app clojure.string/upper-case ?a) & ?the-rest}
;; Default
?x
?x)
@mark340 ☝️ that should do the trick. (Yes I know &
is missing docs.)
Ah! &
is definitely the missing piece for me. Thanks!