Fork me on GitHub
#meander
<
2022-01-13
>
Ben Sless13:01:11

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

ribelo13:01:59

IIRC m/some also works on rhs

Ben Sless13:01:43

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?

ribelo13:01:10

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

ribelo14:01:23

@ben.sless

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

😨 1
ribelo14:01:49

unfortunately m/some does not work on rhs

ribelo14:01:06

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

Ben Sless15:01:52

GOT IT

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

Ben Sless15:01:06

will do it anyway

Ben Sless15:01:50

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 Sless17:01:25

Thanks borkdude, we now have a starting point

❤️ 1