Clojure - Predicates every-pred


Advertisements

Takes a set of predicates and returns a function ‘f’ that returns true if all of its composing predicates return a logical true value against all of its arguments, else it returns false.

Syntax

Following is the syntax.

(every-pred p1 p2 .. pn)

Parameters − ‘p1 p2...pn’ is the list of all predicates which need to be tested.

Return Value − Returns true if all of its composing predicates return a logical true value against all of its arguments, else it returns false.

Example

Following is an example of every-pred in Clojure.

(ns clojure.examples.example
   (:gen-class))
(defn Example []
   (println ((every-pred number? even?) 2 4 6))
   (println ((every-pred number? odd?) 2 4 6)))
(Example)

Output

The above program produces the following output.

true
false
clojure_predicates.htm
Advertisements