Predicates are functions that examine a condition and send a boolean value (true or false). We have predicate functions like the even number. You can search for these shots to see their functionality as each predicate function has been treated in detail separately.
some
function?The some
function takes in a predicate method to evaluate the parameter passed. While evaluating the parameters, the some
function returns true
on the first parameter that satisfies the predicate method.
(some? p1 pn)
Here, p1
is the predicate function and pn
is the parameter to be tested.
The some
function receives a predicate function to evaluate the passed parameter, as we will see in an example shortly.
The some
function returns true
once it finds the parameter that satisfies the predicate method. It returns nil
if none of the parameters satisfies the predicate method.
(ns clojure.examples.example(:gen-class))(defn func [](println (some zero? '(2 4 6))))(func)
func
.(zero)
alongside the some
function to evaluate the passed parameter 2 4 6
. Then, we print out the output. Notice that the output is nil
because even though the values passed are numbers, all values fail the test by the zero
predicate function because the zero
predicate function checks to see if a number is zero.func
function.