Clojure: testing each value from a map operation for truth

How to check that every value in the collection returned by map is true?

I am using the following:

 (defn test [f coll] (every? #(identity %) (map f coll))) 

with the anonymous function #(identity %) , but I was wondering if there is a better way.

I cannot use (apply and ...) because and is a macro.

UPDATE : By the way, I am making my way across the Haskell road to logic, math and programming, Kees Doets and Jan can Age, but doing the exercises in Clojure. This is a very interesting book.

+4
source share
2 answers

You can do:

 (every? true? coll) 
+4
source

or

 (every? identity (map f coll)) 

or

 (every? f coll) 
+5
source

Source: https://habr.com/ru/post/1333906/


All Articles