This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use the `where` method to implement the filters. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main() { | |
var numbers = [1, 3, -2, 0, 4, 5]; | |
var numbersUntilZero = numbers.takeWhile((number) => number != 0); | |
print('Numbers until 0: $numbersUntilZero'); | |
var numbersAfterZero = numbers.skipWhile((number) => number != 0); | |
print('Numbers after 0: $numbersAfterZero'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main() { | |
var evenNumbers = [1, -2, 3, 42].where((number) => number.isEven); | |
for (var number in evenNumbers) { | |
print('$number is even.'); | |
} | |
if (evenNumbers.any((number) => number.isNegative)) { | |
print('evenNumbers contains negative numbers.'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use the methods `any` and `every` to compare the user age. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
var items = ['Salad', 'Popcorn', 'Toast']; | |
if (items.any((element) => element.contains('a'))) { | |
print('At least one element contains "a"'); | |
} | |
if (items.every((element) => element.length >= 5)) { | |
print('All elements have length >= 5'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use the methods `contains` and `startWith` from the `String` class. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool predicate(String element) { | |
return element.length > 5; | |
} | |
main() { | |
var items = ['Salad', 'Popcorn', 'Toast']; | |
// You can find with a simple expression: | |
var element1 = items.firstWhere((element) => element.length > 5); | |
print(element1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
var iterable = ['Salad', 'Popcorn', 'Toast']; | |
print('The first element is ${iterable.first}'); | |
print('The last element is ${iterable.last}'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
var iterable = ['Salad', 'Popcorn', 'Toast']; | |
for (var element in iterable) { | |
print(element); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Let's do a Hello World |