Skip to content

Instantly share code, notes, and snippets.

@bsless
Created May 26, 2020 12:40
Show Gist options
  • Select an option

  • Save bsless/c87632f6215ac86debfe93e02b505766 to your computer and use it in GitHub Desktop.

Select an option

Save bsless/c87632f6215ac86debfe93e02b505766 to your computer and use it in GitHub Desktop.
Eager cartesian product between two seqs in Clojure
(defn- pair
[k v]
(clojure.lang.MapEntry. k v))
(defn prod
[xs ys]
(persistent!
(reduce
(fn [acc x]
(reduce
(fn [acc' y]
(conj! acc' (pair x y)))
acc
ys))
(transient [])
xs)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment