tags:

views:

119

answers:

3

I want to apply a series of tests on my list and make sure that all the tests are passed. Is there a function similar to "andmap" in Clojure?

+5  A: 

You could use every?:

user=> (every? string? '("hi" 1))
false

Here's the documentation on every?.

Pinochle
A: 

(every? will ask "does this one function return true for each memeber of the seq, which is close to what I think you are asking for. An improvement on every? would take a list of functions and ask "are all these predicates true for every member of this seq"

here is a first attempt:

(defn andmap? [data tests] 
    (every? true?
        (map (fn [test] (every? true? (map (fn [data] (test data)) data)))
            tests)))

>(andmap? '(2 4 8) [even? pos?])
true
>(andmap? '(2 4 8) [even? odd?])
false
Arthur Ulfeldt
A: 
Jonas