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

android - net_scheduler holding wakelock -

sql - MySQL : Getting Entries from a many-to-many table -

java - Retrieving data from database using jsp (Hibernate + Spring + Maven) -