Alternative implementation using combinatorics
(require '[clojure.math.combinatorics :as combo])
(defn f
[keys vals n]
(->> (combo/cartesian-product (combo/combinations keys n)
(combo/selections vals n))
(map (partial apply zipmap))
set))
> (f [:a :b :c] [1 2] 2)
=> #{{:c 2, :a 1} {:c 1, :a 1} {:c 2, :a 2} {:b 1, :a 1} {:c 1, :a 2} {:b 2, :a 1} {:c 2, :b 1} {:c 1, :b 1} {:c 2, :b 2} {:b 1, :a 2} {:c 1, :b 2} {:b 2, :a 2}}