Skip to content

Instantly share code, notes, and snippets.

Created Oct 27, 2016
What would you like to do?
Create map from alternating series of keys and values
(defn make-pairs
"Creates a vector of pairs from the incoming sequence. Ignores extra elements."
([] []) ; return an empty vector if supplied no arguments
([seq] (make-pairs seq [])); return a vector of pairs taken from seq
([seq pairs] ; return a vector of pairs, starting with some existing pairs
(if (< (count seq) 2) pairs
(make-pairs (rest (rest seq))
(conj (vec pairs) [(first seq) (second seq)])))))
(defn map-pairs
"Creates a map from pairs of values from seq. Ignores extra elements."
(into {} (make-pairs seq)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment