Clojure - how to do reductions function but drop state?

Viewed 237

If I use the reductions function like so:

(reductions + [1 2 3 4 5])

Then I get

(1 3 6 10 15)

Which is great - but I'd like to apply a binary function in the same way without the state being carried forward - something like

(magic-hof + [1 2 3 4 5])

leads to

(1 3 5 7 9)

ie it returns the operation applied to the first pair, then steps 1 to the next pair.

Can someone tell me the higher-order function I'm looking for? (Something like reductions)

This is my (non-working) go at it:

(defn thisfunc [a b] [(+ a b) b])

(reduce thisfunc [1 2 3 4 5])
4 Answers
Related