Skip to content

Instantly share code, notes, and snippets.

Created September 7, 2015 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/041dc81e168f176c7ab1 to your computer and use it in GitHub Desktop.
Save anonymous/041dc81e168f176c7ab1 to your computer and use it in GitHub Desktop.
(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