Skip to content

Instantly share code, notes, and snippets.

@rafaelfelini
Forked from paulosuzart/ltm.clj
Created December 15, 2011 00:27
Show Gist options
  • Save rafaelfelini/1479261 to your computer and use it in GitHub Desktop.
Save rafaelfelini/1479261 to your computer and use it in GitHub Desktop.
Makes a clojure Map from a given coll.
(defn ltm
"Makes a clojure map from a given collection. lst should have an even number of elements"
[lst]
(reduce merge
(map (fn [l] {(keyword (str (first l))) (second l)}) (partition 2 lst))))
;;kudos to @paulosuzart
;;user=> (ltm '(:a 1 :b 2 :c3 :d 4))
;;{:c3 :d, :b 2, :a 1}
;;or
;;user=> (ltm '(1 2 3))
;;{:1 2}
;;or
;;user=> (ltm '("name" "paulo" "age" 29))
;;{:age 29, :name "paulo"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment