Skip to content

Instantly share code, notes, and snippets.

@luxbock

luxbock/foo.clj Secret

Last active June 17, 2016 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luxbock/4eb81767e6bb1f6169b4fb12ec8b9356 to your computer and use it in GitHub Desktop.
Save luxbock/4eb81767e6bb1f6169b4fb12ec8b9356 to your computer and use it in GitHub Desktop.
(transform
[ALL
(collect-one :foo)
(collect-one :bar)]
(fn [foo bar _]
(transform [REST ALL]
#(map (partial + foo) %)
bar))
[{:foo 1 :bar [[10] [2 3] [20 30]]}
{:foo 2 :bar [[10] [4 5] [40 50]]}
{:foo 3 :bar [[10] [6 7] [60 70]]}])
;; => [[[10] [3 4] [21 31]] [[10] [6 7] [42 52]] [[10] [9 10] [63 73]]]
(mapv (fn [{:keys [foo bar]}]
(into [(first bar)]
(map #(mapv (partial + foo) %))
(rest bar)))
[{:foo 1 :bar [[10] [2 3] [20 30]]}
{:foo 2 :bar [[10] [4 5] [40 50]]}
{:foo 3 :bar [[10] [6 7] [60 70]]}])
;; => [[[10] [3 4] [21 31]] [[10] [6 7] [42 52]] [[10] [9 10] [63 73]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment