What is the any() function in Julia?
In this shot, we will learn about Julia’s built-in any() function.
Overview
The any() function is a built-in function provided by Julia.
It tests whether any element in the Boolean collection has a true value.
We use the following syntax for this function.
Syntax
any(boolean_collection)
Parameters and returns
The any() function takes a boolean collection as a parameter.
- If any of the values is true in the boolean collection, it returns
true. - If all the non-missing values are false, it returns
missing. - If all values are false, it returns
false.
Let’s use an example to understand it better:
Example
In the following code, we have three examples for three cases as specified in the returns above:
#Refer to point 1 in returnsprintln(any([false, false, true, false]))#Refer to point 2 in returnsprintln(any([false, missing, false]))#Refer to point 3 in returnsprintln(any([false, false, false, false]))
Quiz
Let’s take a small quiz on what we have learned about the any() function so far.
Let’s check our understanding of the any() function in Julia.
Q
What do you think the below code snippet prints?
println(any([false, missing, true]))
A)
true
B)
false
C)
missing