-
-
Save catharinejm/5536358 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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