Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Short form field expressions #822

Open
mnordine opened this issue Feb 6, 2020 · 1 comment
Open

Short form field expressions #822

mnordine opened this issue Feb 6, 2020 · 1 comment
Labels
feature Proposed language feature that solves one or more problems

Comments

@mnordine
Copy link
Contributor

mnordine commented Feb 6, 2020

class User {
  String name;
  int age;
  String? bestFriend;

  User({required this.name, required this.age, this.bestFriend});

  bool get canVote => age >= 18;
}

void main() {
  var john = User(name: 'John Doe', age: 19, bestFriend: 'Mary');
  var mary = User(name: 'Mary Smith', age: 17);
  var users = [john, mary];
  
  // Long form
  var names = users.map((user) => user.name);
  var canVote = users.where((user) => user.canVote);
  var hasBestFriend = users.where((user) => user.bestFriend != null);
  
  // Short form
  var names = users.map(.name);
  var canVote = users.where(.canVote);
  var bestFriends = users.map(.bestFriend); // compile-time error because it's nullable? Use long form instead?
}
@mnordine mnordine added the feature Proposed language feature that solves one or more problems label Feb 6, 2020
@eernstg
Copy link
Member

eernstg commented Feb 6, 2020

Cf. #8 and #265.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems
Projects
None yet
Development

No branches or pull requests

2 participants