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


this question has answer here:

say, have 5 javascript objects stored in vector:

(def v [o1 o2 o3 o4 o5]) 

each o them has method "connect", gets object parameter.

manually now:

o1.connect(o2); o2.connect(o3); o3.connect(o4); o4.connect(o5); 

what approach automate this?

only weird solutions come mind: as:

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

is there better way?

you can use partition:

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

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -