Fork me on GitHub
#meander
<
2020-03-20
>
grounded_sage13:03:19

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

grounded_sage13:03:15

(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

Jimmy Miller13:03:58

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
grounded_sage14:03:04

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

timothypratley15:03:55

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

Jimmy Miller16:03:18

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.

noprompt17:03:03

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.

Jimmy Miller17:03:14

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.

noprompt17:03:01

(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"

noprompt17:03:03

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.

grounded_sage08:03:44

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

noprompt19:03:42

It’s short for apply str with no separator