Fork me on GitHub
#meander
<
2022-01-14
>
noprompt04:01:01

(m/rewrite {:a 'a :b nil}
  {:a ?a & (m/gather [!k (m/some !v)])}
  {:a ?a & [[!k !v] ...]})
;; =>
{:a a}

(m/rewrite {:a 'a :b nil :c 'c :d nil}
  {:a ?a & (m/gather [!k (m/some !v)])}
  {:a ?a & [[!k !v] ...]})
;; =>
{:a a, :c c}

noprompt04:01:34

You can use m/gather for this kind (it works the best for memory variables).

noprompt04:01:18

That pattern is the same as writing

{:a ?a & (m/seqable (m/or [!k (m/some !v)] _) ...)}

noprompt04:01:08

More verbosely

(m/rewrite {:a 'a :b nil :c 'c :d nil}
  {?k nil & (m/cata ?m)}
  ?m
  
  {?k ?v & (m/cata ?m)}
  {?k ?v & ?m}

  {}
  {})
;; =>
{:a a, :c c}
Pattern match on the ?k nil first.