Fork me on GitHub
#meander
<
2020-06-10
>
Dustin Getz01:06:11

(def body2 [1 2 3 '=> nil
              5 6 '=> nil
              8 '=> nil])

(m/rewrite body2
  (m/scan !xs ..!n '=> ?v)
  [[!xs ..!n] ?v])

; [[1 2 3] nil]
How do I make it return all the matches, not just one? I see rewrites but having trouble

Dustin Getz01:06:14

I got it with cata, but maybe there is a better way

(m/rewrite body2
    [] []
    [!xs ... '=> ?v & ?more]
    [[!xs ... ?v] & (m/cata ?more)])

; [[1 2 3 nil] [5 6 nil] [8 nil]]

Jimmy Miller02:06:15

I think cata is the way I'd recommend.