Skip to content

Instantly share code, notes, and snippets.

@cbilson
Created January 31, 2011 14:33
Show Gist options
  • Save cbilson/804099 to your computer and use it in GitHub Desktop.
Save cbilson/804099 to your computer and use it in GitHub Desktop.
;; 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