Last active
May 2, 2020 04:56
-
-
Save johnwesonga/a3d517fc5f9e2e63ff749f46cb9a6be5 to your computer and use it in GitHub Desktop.
Clojure: Convert vector to map
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
(def header-lines ["Host: example.com" "User-Agent: ExampleBrowser/1.0" "Accept: */*" | |
"Content-Type: application/x-www-form-urlencoded" "Content-Length: 21"]) | |
(:require '[clojure.string :as str]) | |
(->> (map #(let [[k v] (str/split % #": ")] | |
[(keyword k) v]) header-lines) | |
(into {})) | |
;;str/split function | |
;; splits the key value with ": " | |
;;keyword function | |
(keyword "Host") | |
:Host |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment