Welcome! Please see the About page for a little more info on how this works.
What's the most idiomatic way of writing a function that, given a coll (1 2 3 4 5)
(1 2 3 4 5)
Returns
((1 2) (2 3) (3 4) (4 5))
i.e. consecutive couples of elements in a collection.
My naive solution would be:
(map (fn [a b] [a b]) a (rest a))
partition has an arity with a step argment that does this.
partition
(partition 2 1 [1 2 3 4 5]) ;=> ((1 2) (2 3) (3 4) (4 5))