[英]In clojure, how can I select and return a subset of a collection
If I have a collection like this 如果我有这样的收藏
{{:A "a" :B "b"} {:A "a" :B "Goal" } {:A "a" :B "Goal"}}
how do I make a function so it returns only the parts where :B "Goal"
? 我该如何做一个函数,使其仅返回
:B "Goal"
? Meaning only: 仅含义:
{{:A "a" :B "Goal" } {:A "a" :B "Goal"}}
I fixed your data to make it a vector of 3 maps. 我修正了您的数据,使其成为3张地图的向量。
(def data [{:A "a" :B "b"}
{:A "a" :B "Goal"}
{:A "a" :B "Goal"}])
(defn b-goal?
[item]
(= (:B item) "Goal") )
(filter b-goal? data) => ({:A "a", :B "Goal"} {:A "a", :B "Goal"})
Be sure also to check out: 还要确保签出:
As well as books like 以及像
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.