dart-lang / dart-lang/language
Variadic constructors
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
[Slightly outdated proposal document (from May 2018!)](https://gist.github.com/ds84182/3d54ed9992aaba8e82be556a155fe277)
In short, variadic constructors would allow custom collection types (incl TypedData) to be created directly from a lazy evaluated iterable or list (depending on the type specified in the constructor).
This would be great for initializing typed data, and could also be extended to allow for some restricted constness (const typed data!!). It could also make Flutter build methods slightly more concise:
```dart
Widget build(BuildContext context) {
return Row [
Text("foo"),
Text("bar"),
];
}
```
The only downside is that named parameters can't be passed to Row using this syntax.
Perhaps a different approach can be taken for defining the variadic constructors themselves (like `class Foo { Foo[E data...] {} }`.
Maps could also benefit from this syntax, so custom map collection types can be initialized using the familiar map syntax: `BuiltMap { "foo": bar }`
Contributor guide
Research direction
Start with the linked May 2018 proposal and the discussion in this issue. Determine whether variadic constructors should cover lists, lazy iterables, maps, and const typed data, and identify the language specification areas affected. Done means the syntax and semantics are agreed and documented consistently.
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
- Mostly clear
- Newbie friendliness
- 25/100