Fork me on GitHub
#clojure-austin
<
2016-09-22
>
clojuregeek16:09:39

is there a better way to take a map with string keys and convert to keyword keys?

clojuregeek16:09:50

5 │ (defn props []
   6 │   (let [file (io/file "field-map.properties")
   7 │         data (p/load-from file)]
   8 │     (zipmap (map keyword (keys data)) (vals data)) ))

clojuregeek16:09:32

{"two" "dos", "one" "uno", "three" "a long thing"} is what would be in data

norman17:09:23

There’s fmap

norman17:09:32

in contrib… let me see

norman17:09:12

actually - no fmap is for map keys

norman17:09:32

(into {} (for [[k v] data] [(keyword k)] v)

norman17:09:03

That’s an option, but zipmap reads pretty well

norman17:09:33

(clojure.walk/keywordize-keys data)

clojuregeek17:09:42

hmm so its not actually a map but a java.util.Properties object ...

clojuregeek17:09:47

playing in repl

clojuregeek17:09:09

a is my object

(clojure.walk/keywordize-keys (into {}  a))

clojuregeek17:09:04

ok thanks 🙂

clojuregeek17:09:00

ok i have another question

clojuregeek17:09:17

i am making a war file and handing it to a guy

clojuregeek17:09:37

that reads a properties file ... using clojurewerkz/propertied library ...

clojuregeek17:09:56

if I read the file and store into a variable

clojuregeek17:09:09

and compile to jar ....

clojuregeek17:09:15

will the var work ?

clojuregeek17:09:33

or will it contain the values it had when i first compiled ?

clojuregeek17:09:22

i guess i can try it

clojuregeek18:09:14

hmm i used clojure.walk by calling it fully qualified.. and when i make uberjar it complains

norman18:09:54

Did you require it?

clojuregeek19:09:17

ok it works now 😉

clojuregeek19:09:10

and i answered my own questions 🙂

clojuregeek19:09:09

clojure is the most awesome language

clojuregeek20:09:17

mainly for a reference during the workshop