-
Hey! I hope you're having a great day. I'm trying to figure out how to grab every item in this deep structure and return a flattened result.
gives me |
Beta Was this translation helpful? Give feedback.
Answered by
noprompt
Sep 10, 2021
Replies: 1 comment 5 replies
-
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 arg
[[?t {:active (m/map-of _ {:ids (m/gather {:business !a})})}]
& ?rest]
([?t [!a ...]] & (m/cata ?rest))
_else ())
;; WRONG! IGNORE!
(m/rewrite arg
(m/gather [!t {:active (m/map-of _ {:ids (m/gather {:business !a} !n)})}])
([!t [!a ..!n]] ...)) |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
rgkirch
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One solution would be to recursively handle each element of the input sequence:
From here we can switch to
m/rewrite
and usem/cata
on the right.