Home Ask Login Register

Developers Planet

Your answer is one click away!

Anton Harald February 2016

iterate a sequence, accessing current item and the following in each step

say, I have 5 javaScript Objects stored in a vector:

(def v [o1 o2 o3 o4 o5])

Each o them has a method "connect", which gets another object as a parameter.

Manually I would now:


What would be a good approach to automate this?

only some weird solutions come to my mind: as:

(doseq [[a b] (zipmap (butlast v) (rest v))]
  (.connect a b))

is there a better way?


Lee February 2016

You can use partition:

(doseq [[a b] (partition 2 1 v)]
  (.connect a b))

Post Status

Asked in February 2016
Viewed 1,790 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life