Skip to content

Instantly share code, notes, and snippets.

@rauhs
Last active November 24, 2016 17:51
Show Gist options
  • Select an option

  • Save rauhs/52d11ec6e7521030fbf86ed06aaec4db to your computer and use it in GitHub Desktop.

Select an option

Save rauhs/52d11ec6e7521030fbf86ed06aaec4db to your computer and use it in GitHub Desktop.
(defn map-all
"Like map but if given multiple collections will call the function f
with as many arguments as there are elements still left."
([f] (map f))
([f coll] (map f coll))
([f c1 & colls]
(let [step (fn step [cs]
(lazy-seq
(let [ss (keep seq cs)]
(when (seq ss)
(cons (map first ss)
(step (map rest ss)))))))]
(map #(apply f %) (step (conj colls c1))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment