All
The All function is a boolean aggregate function that determines whether all elements in a collection satisfy a specified condition. It returns true if every element meets the criteria, or false if any element fails the condition.
Function Name: All
Return Type: Boolean
Syntax
The All function can be called with the following syntax:
Basic Syntax:
All(collection, criteria)
Named Parameter Syntax:
All(collection -> <collection_expression>, criteria -> <lambda_expression>)
Parameters
Parameter |
Type |
Required |
Description |
|---|---|---|---|
|
Collection |
Yes |
The collection of elements to evaluate. Can be an array, query result, or any collection expression. |
|
Lambda |
Yes |
A lambda expression that defines the condition each element must satisfy. Takes one parameter representing the current element and returns a boolean. |
Return Value
Type:
Boolean- Returns:
trueif all elements in the collection satisfy the criteriatrueif the collection is emptyfalseif any element fails to satisfy the criteria
Evaluation Rules
The All function follows these evaluation rules:
Short-Circuit Evaluation: Stops evaluating as soon as any element fails the criteria and returns
falseEmpty Collections: Returns
truefor empty collections (vacuous truth)Null/Undefined Handling: Null or undefined values are passed to the criteria lambda; the lambda determines how to handle them
All Must Pass: Every single element must satisfy the criteria for the function to return
trueBoolean Criteria: The criteria lambda must return a boolean value
Order of Evaluation: Elements are evaluated in the order they appear in the collection
Use Cases
The All function is useful for:
Validation: Verifying that all items in a collection meet required criteria
Quality Checks: Ensuring all data meets quality standards
Business Rules: Validating that all entities satisfy business rules
Preconditions: Checking that all elements meet prerequisites before processing
Data Integrity: Verifying data consistency across collections
Filtering Verification: Confirming that filtering logic worked correctly
Examples
{
"Comment_All_1": "Check if salaries of all employees older than 40 is greater than 85000.",
"All_1": "$value(All(Companies.Select(c => c.Employees).Where(e => e.Age >= 40), e => e.Salary > 85000))",
"Comment_All_2": "Another way to check if salaries of all employees older than 40 is greater than 85000.",
"All_2": "$value(All(Companies.Select(c => c.Employees), e => e.Age < 40 || e.Salary > 85000))",
"Comment_All_3": "Demo of using named parameters to make the intent clear.",
"All_3": "$value(All(collection -> Companies.Select(c => c.Employees), criteria -> e => e.Age < 40 || e.Salary > 85000))"
}