Fork me on GitHub
#meander
<
2020-04-04
>
markaddleman02:04:55

Trying to up my meander game.:

(m/rewrite {:g1 [{:k :a :v 1} {:k :b :v 2}]
              :g2 [{:k :b :v 2} {:k :a :v 1}]}

             (m/and
               {:g1 (m/seqable {:k !k :v !v1} ...)
                :g2 (m/seqable {:k !k :v !v2} ...)})
             [!k (m/app + !v1 !v2) ...])
I'd like the result to be [:a 2 :b 4 but meander is walking the two seqs independently. How do I get a join on :k ?

noprompt19:04:33

(m/rewrite {:g1 [{:k :a :v 1} {:k :b :v 2}]
            :g2 [{:k :b :v 2} {:k :a :v 1} {:k :b :v 3}]}
  {:g1 (m/seqable !g1s ...)
   :g2 (m/seqable !g2s ...)}
  (m/cata [!g1s ... !g2s ...])

  [] []

  (m/with [%m {:k ?k
                :v !v}]
    [%m . (m/or %m !not-m) ...])
  [?k ~(reduce + !v) & (m/cata [!not-m ...])])
;; =>
[:a 2 :b 7]

noprompt19:04:39

There are probably few other ways to do this.

noprompt19:04:56

Again, this is another place where the zeta fold will come in handy.