Fork me on GitHub
#meander
<
2021-02-03
>
ribelo00:02:46

How do I get something like this?

[:a 1 2 3 :b 4 5 :c 6 7 8 9 ...]
;; => {:a [1 2 3] :b [4 5] :c [6 7 8 9] ...}

jimmy03:02:15

This one in the cookbook is pretty easy to modify to give you want you what you are looking for. https://github.com/noprompt/meander/blob/epsilon/doc/cookbook.md#multiple-variable-length-sub-sequences

(m/rewrite [:a 1 2 3 :b 4 5 :c 6 7 8 9]
  [] [] ; The base case for no values left
  [(m/pred keyword? ?x) . (m/pred int? !ys) ... & ?more]
  {& [[?x [!ys ...]] & (m/cata ?more)]})

ribelo07:02:27

I looked at this but I still have trouble bending my mind around cata & recursion

ribelo07:02:42

Thanks as always!

ribelo19:02:01

How to check if a map does not have a given key?

(m/rewrite {:m        {:a 1 :b 2 :c 3}
            :selector :c}
  {:m        {?s ?k}
   :selector ?s} true)
;; => true

(m/rewrite {:m        {:a 1 :b 2}
            :selector :c}
  {:m        {?s nil}
   :selector ?s} true)
;; => nil

(m/rewrite {:m        {:a 1 :b 2}
            :selector :c}
  {:m        (m/not {?s ?k})
   :selector ?s} true)
;; => nil

jimmy20:02:36

(m/rewrite {:m {:a 1 :b 2}
            :selector :d}

  {:selector ?s
   :m (m/not {?s (m/some)})}

  true)
Just need to use a some here. Meander will match for keys that don’t exist. Changing this behavior is on my personal wish list for zeta.

ribelo20:02:00

I was close!