Created
October 27, 2016 20:31
-
-
Save benton/66e5b7aca8a8522f44e16cc657d27fe7 to your computer and use it in GitHub Desktop.
Create map from alternating series of keys and values
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 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." | |
[seq] | |
(into {} (make-pairs seq))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment