Reputation: 1977
How i can count mobile and web access discarding a nil values from a list of maps? the output should be anything like this " Statistic mobile = 1 web = 2", but all is imutable on other languagens a simple i++ resolve but how is in clojure. thanks.
def data [{:name "app1" :type "mobile" }
{:name "site1" :type "web" }
{:name "site1" :type "web" }
{:name "boot" :type nil }]
Upvotes: 0
Views: 139
Reputation: 33637
user=> (for [[k v] (group-by :type data) :when k] [k (count v)])
(["mobile" 1] ["web" 2])
Upvotes: 1
Reputation: 6681
(frequencies (map :type data))
gives
{"mobile" 1, "web" 2, nil 1}
Upvotes: 7