Last active
July 26, 2020 18:53
-
-
Save JoeCodeswell/18472e3fc8e84ed7ece391b8dc6a3ced to your computer and use it in GitHub Desktop.
List Comprehensions in Dart
This file contains 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
/// [List Comprehensions in Dart](https://medium.com/@DavidMPotter/list-comprehensions-in-dart-a57d3a06b703) | |
/// https://gist.github.com/JoeCodeswell/ListComprehensionsInDart.dart | |
/// /// https://dartpad.dev/18472e3fc8e84ed7ece391b8dc6a3ced | |
/// | |
void main() { | |
var intList = [1, 2, 3, 4]; | |
// py [x + 1 for x in intList] | |
var intListPlus_1 = intList.map((x) => x + 1).toList(); | |
print('intListPlus_1: $intListPlus_1'); | |
// py [x + 10 for x in intList if x % 2 == 1] | |
var oddListPlus_10 = intList.where((x) => x % 2 == 1).map((x) => x + 10).toList(); | |
print('oddListPlus_10: $oddListPlus_10'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment