Created
August 11, 2011 19:35
-
-
Save gtrak/1140545 to your computer and use it in GitHub Desktop.
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
;;These functions are equivalent | |
;; the :as :map isn't quite right, it returns a map with key to a vector of | |
;; values when I should just have key to value, so we adjust it, | |
;; TODO: there must be a better way | |
(defn- headers-to-map1 [headers] | |
(loop [out {} left headers] | |
(let [cur (first left) | |
key (first cur) | |
val (second cur) | |
;;for the recur | |
nleft (next left)] | |
(if (empty? left) out | |
(if (and (vector? val) (= 1 (count val))) | |
(recur (assoc out key (first val)) nleft) | |
;;else just put the value back in | |
(recur (assoc out key val) nleft)))))) | |
(defn- headers-to-map [headers] | |
(into {} (map (fn [[k v]] | |
(if (and (vector? v) (second v)) | |
[k v] | |
[k (first v)])) | |
headers))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment