Predicates examine a condition and send a boolean value (true or false). We have several predicate functions, such as even number
and zero
. You can find shots on predicates and study functionality, as each predicate function has been treated in detail separately.
Let's study the every-pred
function. This function takes in multiple predicate functions to evaluate parameters passed. For instance, we use two predicate functions to test if a number is even and not a string: the even
predicate function and the number
predicate function.
(every-pred p1 p2 .. pn)
Here:
p1
and p2
are the predicate functions.pn
is the parameters to be tested.The every-pred
function receives multiple predicate functions to evaluate the passed parameter.
The every-pred
returns either true
or false
depending on if the passed parameter satisfies all of the predicates function.
(ns clojure.examples.example(:gen-class))(defn func [](println ((every-pred number? zero?) 2 4 6))(println ((every-pred number? even?) 2 4 6)))(func)
func
.(number, zero)
alongside the every-pred
function to evaluate the passed parameter 2 4 6
. Next, we print the output to console. Notice that the output is false
. We use the number
predicate function to check if the passed values, which are numbers, fail the test by the zero
predicate function. We use the zero
predicate function to see if a number is zero.(number, even)
alongside the every-pred
function to evaluate the passed parameter 2 4 6
. Next, we print the output to the console. Notice that the output is true
. We use the number
predicate function to check if the passed values, which are numbers, pass the test by the even
predicate function. We use the even
predicate function to see if a number is even.func
.