dart-lang / dart-lang/language
Add `yield` to collection for
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
I constantly feel that collection for is almost there, but not there. It allows some cool syntax for simple cases, but constantly I need to add just a few more steps, like getting data from an async call, then deciding if I should add it to the list or not.
With the current syntax, we can use {}, so we are restricted to simple 1 line cases.
This made me think that we might (I am not aware of the complexity) combine generators and collection if (at least in the syntax, merging their functionality might make the code more complex or with worse performance), to allow us something like:
Future<List<String>> getStrings() async {
return [
for (final myInt in myInts) {
final myString = await getMyData()
if (myString != null) {
yield myString; // This will signal to the collection for that we are producing a new item.
}
}
];
}
With the yield keyword we could leverage collection if to spread across several lines.
I apologize in advance if I am missing something, I bet I am, as language features are always tricky.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files, tests, or implementation entry points are identified. Start by reviewing the existing collection-for, collection-if, and generator language specifications, then determine whether the proposed yield syntax has defined semantics for async calls and list construction; done would require an agreed language design rather than a localized code change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100