我有一个包含两个键的地图列表:path和:size
listOfMaps ({:path "a " :size "1 "}{{:path "b " :size " 2"}...)
如何迭代它并将其路径和大小连接到一个字符串,以便它位于
之间即
str "initial" "a" "1" "b" "2" .... "end"
即通过循环填充的路径和大小应该在字符串之间" initial"和"结束"
答案 0 :(得分:5)
(apply str
`("initial"
~@(mapcat (juxt :path :size) list-of-maps)
"end"))
答案 1 :(得分:0)
也许它很重但我觉得很有趣
(defn str-values [data]
(as-> data d
(map vec d)
(flatten d)
(remove keyword? d)
(concat ["initial"] d ["end"])
(apply str d)))
输出
"initiala1b2end"
这就是你想要的吗?
修改强> 由OlegTheCat更正
(defn str-values [data]
(as-> data d
(map (juxt :path :size) d)
(flatten d)
(remove keyword? d)
(concat ["initial"] d ["end"])
(apply str d)))