这是一个名为args的假设哈希图:
{:body {:milestones [{:status 1 :otherValues x}
{:status 2 :otherValues z}
{:status 1 :otherValues y]}}
我的目标是为每个:status键收集值。它们都是:milestones的子元素,深度相同。
我越来越近了 我知道如何通过执行以下操作来检索第一个状态的值:
(let [{[{:keys [status]} x] :milestones} :body} args]
(println status))
最远端的目标是找出哪些地图包含值1的:status,并为每个单独的地图创建一个新的集合。
字面上的应用是连接到TeamworkPM并与Google Calenders同步状态为“迟到”或“未完成”的里程碑。
在这种情况下,所需的输出将为{1、2、1}。最终目标是拥有
{{:status 1 :otherValues x}
{:status 1 :otherValues Y}}
尽管我找不到如何将map的向量直接分解为变量的方法,但是您可以先获取的子元素:milestones
,然后使用basicmap
或filter
。
请注意,您可以通过将map用作函数来获取其值。(例如,如果m
是{:key1 "val1"}
,(m :key1)
将是"val1"
)
(def args {:body {:milestones [{:status 1 :otherValues 'x}
{:status 2 :otherValues 'z}
{:status 1 :otherValues 'y}]}})
(let [{{x :milestones} :body} args,
y (map #(% :status) x),
z (filter #(= (% :status) 1) x)
]
(println x) ; [{:status 1, :otherValues x} {:status 2, :otherValues z} {:status 1, :otherValues y}]
(println y) ; (1 2 1)
(println z) ; ({:status 1, :otherValues x} {:status 1, :otherValues y})
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句