Skip to content

Instantly share code, notes, and snippets.

@mecdemort
Created March 28, 2011 13:48
Show Gist options
  • Save mecdemort/890483 to your computer and use it in GitHub Desktop.
Save mecdemort/890483 to your computer and use it in GitHub Desktop.
(defn map-all
"Sequence of results from applying f to the first of each of colls.
Empty colls are dropped and evaluation proceeds."
[f & colls]
(lazy-seq
(when-let [s (seq colls)]
(cons (apply f (map first colls))
(apply map-all f (for [coll (map rest s)
:when (seq coll)]
coll))))))
user> (map-all vector [1 2 3] [4 5] [6])
([1 4 6] [2 5] [3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment