Any, All
Checking if any/all elements of an Iterable, CharSequence or array all matches a given predicates is possible using the below syntax.
Any
List<int> list = [1, 2, 3, 4]
println(when int a in list |> a >= 3) // true
The |>
arrow is used to check if at least one element matches the predicate.
All
List<int> list = [1, 2, 3, 4]
println(when int a in list &> a >= 3) // false
The &>
arrow is used to check if all elements matches the predicate.
Negations
You can also negate those conditions using the !when
keyword.
println(!when int a in list |> a >= 3) // false
println(!when int a in list &> a >= 3) // true
Complex boolean expressions
To use properly the above described operations in boolean expressions, wrap them with the parenthesis to avoid any ambiguity
if ((when int a in list &> a >= 3) && somethingElse) {
doAllTheThings()
}