Skip to content

Instantly share code, notes, and snippets.

@johnwesonga
Last active May 2, 2020 04:56
Show Gist options
  • Save johnwesonga/a3d517fc5f9e2e63ff749f46cb9a6be5 to your computer and use it in GitHub Desktop.
Save johnwesonga/a3d517fc5f9e2e63ff749f46cb9a6be5 to your computer and use it in GitHub Desktop.
Clojure: Convert vector to map
(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