简体   繁体   English

从Clojure中的向量构造地图

[英]Constructing a map from a vector in Clojure

I have a vector that looks like this: 我有一个看起来像这样的矢量:

["Config" "{}" "Auth" "{}" "Other" "{}"]

I'd like to take each key value pair and turn it into the following map: 我想取每个键值对并将其转换为以下映射:

{"Config" "{}", "Auth" "{}", "Other" "{}"}

How can I do this with Clojure? 我怎么能用Clojure做到这一点? Is there a built in function that does this? 是否有内置功能可以做到这一点?

Use apply to apply the map constructor of desired type to the vector, ie : 使用apply将所需类型的地图构造函数应用于向量,即:

(apply hash-map ["Config" "{}" "Auth" "{}" "Other" "{}"])

edit 编辑

According to this answer you can get different map types depending on the way you evaluate {} , so use the map constructor suitable to your needs. 根据这个答案,您可以根据评估{}的方式获得不同的地图类型,因此请使用适合您需要的地图构造函数。

edit 编辑

Looking at this the different object types returned by literal {} appears to be a bug. 看看这个文字{}返回的不同对象类型似乎是一个错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM