Skip to content

Instantly share code, notes, and snippets.

@JoeCodeswell
Last active July 26, 2020 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoeCodeswell/18472e3fc8e84ed7ece391b8dc6a3ced to your computer and use it in GitHub Desktop.
Save JoeCodeswell/18472e3fc8e84ed7ece391b8dc6a3ced to your computer and use it in GitHub Desktop.
List Comprehensions in Dart
/// [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