FORALL
Description
The FORALL function is used to determine whether all elements in an array meet a specified condition. This function takes an array and a single-parameter lambda expression as input and returns a boolean result.
Syntax
Parameter Description
array
: The input array, of typearray<T>
.x -> expr
: A single-parameter lambda expression, wherex
corresponds to an element in the array, andexpr
is an expression that needs to return a boolean value.
Return Result
- Returns a boolean value indicating whether all elements in the array satisfy the condition specified by the lambda expression.
Example
- Determine if all elements in the array are less than or equal to 3:
Result:
- Determine if all elements in the array are greater than 10:
Result:
- Determine if all non-null elements in an array containing null values are less than or equal to 3:
Result:
- Determine if all even elements in the array are greater than or equal to 2:
Result:
Notes
- When the array is empty, the FORALL function will return a
NULL
value. - When the condition in the lambda expression is not satisfied by all elements, the function returns
false
. - When the condition in the lambda expression is satisfied by all elements, the function returns
true
.