Dart Runes skipWhile()
Syntax & Examples
Runes.skipWhile() method
The `skipWhile` method in Dart returns an iterable that skips leading elements of the original iterable while a specified test function is satisfied.
Syntax of Runes.skipWhile()
The syntax of Runes.skipWhile() method is:
Iterable<int> skipWhile(bool test(int value))
This skipWhile() method of Runes returns an Iterable
that skips leading elements while test
is satisfied.
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.skipWhile() returns value of type Iterable<int>
.
✐ Examples
1 Skip lowercase characters
In this example,
- We create a sequence of Unicode code points
runes
from the string 'Hello123'. - We use the
skipWhile
method with a test function to skip all characters with ASCII values less than 97 (lowercase). - We then print the skipped characters to standard output.
Dart Program
void main() {
Runes runes = Runes('Hello123');
Iterable<int> skipped = runes.skipWhile((element) => element < 97);
print('Skipped characters: $skipped');
}
Output
Skipped characters: (101, 108, 108, 111, 49, 50, 51)
2 Skip digits less than 3
In this example,
- We create a sequence of Unicode code points
numbers
from the string '12345'. - We use the
skipWhile
method with a test function to skip all digits less than 3. - We then print the skipped digits to standard output.
Dart Program
void main() {
Runes numbers = Runes('12345');
Iterable<int> skippedDigits = numbers.skipWhile((element) => element < 51);
print('Skipped digits: $skippedDigits');
}
Output
Skipped digits: ()
Summary
In this Dart tutorial, we learned about skipWhile() method of Runes: the syntax and few working examples with output and detailed explanation for each example.