Dart Runes every()
Syntax & Examples
Runes.every() method
The `every` method in Dart checks whether every element of this iterable satisfies a given test function.
Syntax of Runes.every()
The syntax of Runes.every() method is:
bool every(bool test(int element))
This every() method of Runes checks whether every element of this iterable satisfies test
.
Parameters
Parameter | Optional/Required | Description |
---|---|---|
test | required | A function that takes an integer element as input and returns a boolean value indicating whether the element satisfies the test. |
Return Type
Runes.every() returns value of type bool
.
✐ Examples
1 Check for all lowercase characters
In this example,
- We create a sequence of Unicode code points
runes
from the string 'Hello'. - We use the
every
method with a test function to check if all characters are lowercase. - We then print the result to standard output.
Dart Program
void main() {
Runes runes = Runes('Hello');
bool allLowerCase = runes.every((element) => element >= 97 && element <= 122);
print('Are all characters lowercase? $allLowerCase');
}
Output
Are all characters lowercase? false
2 Check for all digit characters
In this example,
- We create a sequence of Unicode code points
numbers
from the string '12345'. - We use the
every
method with a test function to check if all elements are digit characters. - We then print the result to standard output.
Dart Program
void main() {
Runes numbers = Runes('12345');
bool allDigits = numbers.every((element) => element >= 48 && element <= 57);
print('Are all elements digits? $allDigits');
}
Output
Are all elements digits? true
Summary
In this Dart tutorial, we learned about every() method of Runes: the syntax and few working examples with output and detailed explanation for each example.