I've some questions about destructuring a seq of maps, like:
1. Is it possible?
2. If yes, does it have any sense?
3. And if it's possible and is reasonable, how can I do it?
For example, let's say that I have a list of maps like this:
(def something [{:a 1 :b 2}
{:a 2 :b 5}
{:a 3 :b 7}])
And let's say that I want a function that returns the sum of all :a
values of the something seq. I could write the function in this way:
(defn do-sum [some-coll]
(reduce + (map #(:a %) some-coll)))
Not a big deal, but I wonder if there is a better way to do it.
Destructuring could be one answer I thought, since I need only the value
corresponding to the :a key of every map in the seq. But I didn't
figured out how to do it yet.
Any ideas?
Manuel
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en