Created
September 7, 2015 19:35
-
-
Save anonymous/041dc81e168f176c7ab1 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 transform | |
"Zips keys and values together" | |
[dict] | |
(let [[x y & z] (partition-all (count dict) (mapcat vec (for [[k v] dict] | |
(map (fn[e] assoc {} [k e] ) v)))) | |
result (sort-by first (map vector x y ))] | |
(if (= (count z) 1 ) | |
(let [m (drop-last result) | |
r (last result) | |
qw (conj r (apply vec (first z)))] | |
(conj m qw)) | |
result))) | |
;call (transform {:a [34 56 7] :b [21 87 999] :c [3] :d [2 4] :s[4]}) | |
;result ([[:a 7] [:d 2]] [[:a 34] [:b 999]] [[:a 56] [:c 3]] [[:b 21] [:d 4]] [[:b 87] [:s 4]]) | |
;I want pairs of a with pairs of b etc with single pairs put onto the end of the lest vector of pair like this: | |
;([[:a 56] [:b 87] [:c 3]] [[:a 7] [:b 999]] [[:a 34] [:b 21]]) notice the ordering of the pairs within each vector match up. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment