Clojure: Convert hash-maps key strings to keywords?

后端 未结 1 758
情话喂你
情话喂你 2021-02-11 14:30

I\'m pulling data from Redis using Aleph:

(apply hash-map @(@r [:hgetall (key-medication id)]))

The problem is this data comes back with string

1条回答
  •  离开以前
    2021-02-11 15:13

    There is a handy function called keyword that converts Strings into the appropriate keywords:

    (keyword "foo")
    => :foo
    

    So it's just a case of transforming all the keys in your map using this function.

    I'd probably use a list comprehension with destructuring to do this, something like:

    (into {} 
      (for [[k v] my-map] 
        [(keyword k) v]))
    

    0 讨论(0)
提交回复
热议问题