meander

Ben Sless 2022-01-13T13:08:11.007100Z

Is there a way in meander to not add a matched value to the result if it's nil?

2022-01-13T13:24:59.007400Z

IIRC m/some also works on rhs

Ben Sless 2022-01-13T13:36:43.009300Z

How would that look like if I'm matching {:x ?x :y ?y} and want to rewrite as {:x ?x :y ?y} if ?y is some and {:x ?x} if not?

2022-01-13T13:44:10.009500Z

when I'm at the computer later, I'll take a look

2022-01-13T14:01:23.009800Z

@ben.sless

(me/rewrite {:a 1 :b 2 :c 3}
  {:a ?a :d ?d}
  {& [[:aa ?a] ~(if ?d [:dd ?d])]})

😨 1
2022-01-13T14:01:49.010200Z

unfortunately m/some does not work on rhs

2022-01-13T14:02:06.010400Z

and even worse, I am getting old because my memory is failing ; P

Ben Sless 2022-01-13T15:44:52.011100Z

GOT IT

(m/rewrite {:a 'a :b nil}
  {:a ?a :b ?b} {:a ?a & ~@(if ?b [[:b ?b]])})

Ben Sless 2022-01-13T15:45:02.011300Z

Feels evil

Ben Sless 2022-01-13T15:45:06.011500Z

will do it anyway

Ben Sless 2022-01-13T15:48:50.011700Z

Even better:

(m/rewrite {:a 'a :b nil :c 3}

  {:a ?a :b ?b :c ?c}
  {:a ?a
   & ~[(if ?b [:b ?b])
       (if ?c [:c ?c])]})

👍 1
Ben Sless 2022-01-13T17:57:25.012100Z

Thanks borkdude, we now have a starting point

❤️ 1