2010/1/21 Chris Kent <cjk...@gmail.com>: > partition creates a sequence of sequences of adjacent values > > user=> (partition 2 (range 1 7)) > ((1 2) (3 4) (5 6)) > > and you can apply reduce to each of the sequences using map > > user=> (map #(reduce + %) (partition 2 (range 1 7))) > (3 7 11) > > or > > user=> (map (partial reduce + ) (partition 2 (range 1 7))) > (3 7 11)
For a slightly different (but less general, perhaps) version, there's also: (map (fn [[a b]] (+ a b)) (partition 2 (range 1 7))) By the way, don't get caught out by this: user=> (partition 2 (range 1 7)) ((1 2) (3 4) (5 6)) user=> (partition 2 (range 1 8)) ((1 2) (3 4) (5 6)) user=> (partition 2 (range 1 9)) ((1 2) (3 4) (5 6) (7 8)) -- Michael Wood <esiot...@gmail.com> -- 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