Fork me on GitHub
#meander
<
2020-07-27
>
dominicm09:07:19

(into {} (m/search {:a nil :b 10 :c 20 :d nil}
                   {?k (m/some ?v)} {?k ?v})) ;; {:b 10, :c 20}
I feel like there's going to be a neater solution to this?

Jimmy Miller14:07:46

(m/rewrite {:a nil :b 10 :c 20 :d nil}
  (m/gather [!k (m/some !v)])
  {& [[!k !v] ...]})
There's another way of doing it.

Jimmy Miller14:07:17

Oh wait, forgot about map-of

(m/rewrite {:a nil :b 10 :c 20 :d nil}
  (m/gather [!k (m/some !v)])
  (m/map-of !k !v))

dominicm16:07:38

ah, so gather is the proper way to collect the keys such that I can then map-of with them. I tried map-of a lot and got nowhere.

dominicm16:07:54

I'm guessing gather actually iterates, whereas search is going pair-by-pair?

Jimmy Miller18:07:58

Yeah in this case gather is equivalent to

(m/rewrite {:a nil :b 10 :c 20 :d nil}
  (m/seqable (m/or [!k (m/some !v)] _) ...)
  (m/map-of !k !v))