In Clojure, what would be the nicest way to have a sliding window over a (finite, not too large) seq? Should I just use drop
and take
and keep track of the current index or is there a nicer way I'm missing?
views:
95answers:
2
+2
A:
If you want to operate on the windows, it can also be convenient to do this with map:
user=> (def a [3 1 4 1 5 9])
user=> (map (partial apply +) (partition 3 1 a))
(8 6 10 15)
user=> (map + a (next a) (nnext a))
(8 6 10 15)
Timothy Pratley
2009-09-16 00:52:05