I was browsing the 6-24 Clojure-log archive and ran across an invitation from Craig Andera:

I’ve knocked out a quick definition of something that computes the Cartesian cross product of multiple sequences. But as always when I write Clojure, I have to assume someone else can do it in less code. Anyone care to take a look? http://gist.github.com/451734

So I took a look. As luck would have it, that morning I been thinking about the reduce function, and reduce was exactly the tool needed for Craig’s challenge. Here’s my version.

(defn cross-prod [& colls]
  (->> colls
       (reduce #(for [x %1 y %2] [x y]))
       (map flatten)))

Antoine de Saint-Exupery famously remarked that “perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away”. I think he would have appreciated Clojure.