Fork me on GitHub

Is it possible to take a map as input and selectively transform the values of some keys without specifying the entirety of the map.


(m/match {:one 1
          :two "2"
          :thre 3}
   :two (m/app Integer. ?two)
   :two ?two
Obviously the dots not doing what they normally do in meander lol


On my phone so can't give a full example. But you can use {& ?rest} to capture the rest of a map. So just put all the rest of your matches above that and use rewrite.

👍 4

How do I apply this in a rewrite (apply str (interpose "," [?desc_1 ?desc_2 ?desc_3]))


You can either use ~(f ?x) to force evaluation or (m/app f ?x) to use substitutive evaluation


But also you don't have the use rewrite for the map stuff above if you don't want to. You can still use {patterns & ?rest} on the left hand side and then something like (merge {:x (m/app ?x} ?rest) on the right hand side. I think rewrite is super useful, but it isn't required.


The question was how to do it. 🙂

(me/rewrite [1 2 3]
  [& _ :as ?xs]
  (me/app interpose " " ?xs))
;; =>
(1 " " 2 " " 3)
On the RHS me/app will apply substitution to all the arguments after the function.


I'm guessing the confusing part was the apply str and the multiple logic variables. You can always wrap functions up in a lambda or make them a defn if you want though.


(me/rewrite [", " [1 2 3] [:a ::c]]
  [?sep [!xs ...] [!ys ...]]
  (me/app clojure.string/join (me/app interpose ?sep [!xs !ys ...])))
;; =>
"1, :a, 2, :b, 3, :c"


This works but its the gross sort of thing we should be able to avoid in zeta when have all of the byte/`string` stuff off the ground.


Thanks for the tips. It is somewhat tricky finding a nice clean solution. I did forget about string join though! Haha


It’s short for apply str with no separator