Skip to content

help a beginner; it's good for your health #208

Answered by noprompt
rgkirch asked this question in Q&A
Discussion options

You must be logged in to vote

One solution would be to recursively handle each element of the input sequence:

(let [r2 [[0 {:active {:a {:ids [{:business "123"}
                                 {:business "aha"}]}
                       :b {:ids [{:business "234"}]}}}]
          [1 {:active {:d {:ids [{:business "567"}]}
                       :c {:ids [{:business "678"}]}}}]]
      f (fn rec [arg]
          (m/find arg
            [[?t {:active (m/map-of _ {:ids (m/gather {:business !a})})}]
             & ?rest]
            (cons [?t !a] (rec ?rest))))]
  (f r2))
;; =>
'([0 ["123" "aha" "234"]] [1 ["567" "678"]])

From here we can switch to m/rewrite and use m/cata on the right.

(m/rewrite arg
  [[?t {:active (m/map-of

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@rgkirch
Comment options

@rgkirch
Comment options

@noprompt
Comment options

@rgkirch
Comment options

@rgkirch
Comment options

Answer selected by rgkirch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants