meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
grounded_sage 2020-03-20T13:52:19.300900Z

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_sage 2020-03-20T13:55:15.303700Z

(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 2020-03-20T13:55:58.304500Z

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.

πŸ‘ 1
grounded_sage 2020-03-20T14:54:04.305Z

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

grounded_sage 2020-03-21T08:06:44.001300Z

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

noprompt 2020-03-21T19:35:42.002Z

It’s short for apply str with no separator

timothypratley 2020-03-20T15:21:55.305200Z

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

jimmy 2020-03-20T16:53:18.305400Z

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.

noprompt 2020-03-20T17:13:03.305600Z

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 2020-03-20T17:15:14.305800Z

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.

noprompt 2020-03-20T17:16:01.306Z

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

noprompt 2020-03-20T17:17:03.306200Z

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.