Skip to content

Instantly share code, notes, and snippets.

@catharinejm
Forked from alandipert/subset.clj
Created May 7, 2013 21:36
Show Gist options
  • Save catharinejm/5536358 to your computer and use it in GitHub Desktop.
Save catharinejm/5536358 to your computer and use it in GitHub Desktop.
(defn pairs-seq [m]
(->> (keys m)
(mapcat #(partition 2 (interleave (repeat %) (get m %))))))
(defn subset [m n]
(reduce #(update-in %1 [(first %2)] (fnil conj []) (second %2)) {}
(take n (pairs-seq m))))
(def m1 {:x [1 2] :y [3 4] :z [5]})
(subset m1 3) ;=> {:y [3 4], :z [5]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment