Created
January 31, 2011 14:33
-
-
Save cbilson/804099 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
;; I came up with this after reading http://stackoverflow.com/questions/1009037/processing-pairs-of-values-from-two-sequences-in-clojure | |
(defn nseq-map | |
"Given keys and sequences of values, produces a sequence of | |
maps of the keys to each slice of values from the sequences. | |
Example: | |
user> (nseq-map [:a :b :c] [1 2 3] [\"ba\" \"bb\" \"bc\"] [\"cx\" \"cy\" \"cz\"]) | |
({:c \"cx\", :b \"ba\", :a 1} {:c \"cy\", :b \"bb\", :a 2} {:c \"cz\", :b \"bc\", :a 3})" | |
[keys & value-seqs] | |
(->> (apply interleave value-seqs) | |
(partition (count value-seqs)) | |
(map #(zipmap keys %)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment