Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure: Testing every value from map operation for truth

How can I test 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: BTW, I am making my way through The Haskell Road to Logic, Maths, and Programming, by Kees Doets and Jan can Eijck, but doing the exercises in Clojure. It's a very interesting book.

like image 751
Ralph Avatar asked Jan 21 '23 20:01

Ralph


1 Answers

either

(every? identity (map f coll)) 

or

(every? f coll)
like image 67
John Lawrence Aspden Avatar answered Jan 30 '23 21:01

John Lawrence Aspden