-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Dart 3 core library additions #49928
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
Comments
Maybe add a |
With records being a thing, we may want to embrace them. We have a number of "indexed" iterable extensions in extension IterableExtension<T> on Iterable<T> {
Iterable<(int, T)> get indexed sync* {
var index = 0;
for (var element in this) yield (index++, element);
}
} Then you would be able to do: for (var (i, e) in something.indexed) {
print("#$i: $e");
} (We'll be missing some affordances in the first release, for example we probably won't have patterns in parameters, so not everything will be as smooth as the We should consider whether there are other uses of records that afford a similar big result for a small effort. |
Usually this one is mentioned as well: extension MapExtension<K, V> on Map<K, V> {
Iterable<(K, V)> get keyed sync* {
for (var element in this.entries) yield (element.key, element.value);
}
}
// Example usage.
void main() {
var map = {1: "one", 2: "two"};
for (var (key, value) in map.keyed) {
print('$key: $value');
}
} |
The You can do (It would be nice to make |
The |
If I could ask for anything crazy in Dart 3, I would go with print("value is", a). I alwaaays struggle with Dart syntax, and it is possible to implement that without varargs. Since print is not supposed to run in release mode, the minimal performance impact is negligible. |
Hey @lrhn can you please check the list at the top (which I updated) to see if it's complete for 3? |
LGTM. |
Uh oh!
There was an error while loading. Please reload this page.
Generally it's hard to evolve the Dart core libraries, as most changes tend to be potentially widely breaking. For example, adding a new member to a class in the core libraries can be breaking to any code that that implements that class, given all Dart classes are implicit interfaces.
While we still don't want major breaking changes in Dart 3 outside of the non-null discontinuation, we have an opportunity to be mildly breaking.
Add
DateTime.timestamp()
constructor for "now as UTC":https://dart-review.googlesource.com/c/sdk/+/292003
Add
Iterable.nonNulls()
as an extension to Iterable indart:core
(currently inpackage:collection
as an extension).https://dart-review.googlesource.com/c/sdk/+/290760
Add
Iterable.firstOrNull
/Iterable.lastOrNull
/Iterable.elementAtOrNull()
as extension methods to Iterable indart:core
(some currently inpackage:collection
as an extension):https://dart-review.googlesource.com/c/sdk/+/290760
Add
DateTime.copyWith()
. Long standing request. As an extension method, to avoid breakage.https://dart-review.googlesource.com/c/sdk/+/258541
records related changes: [Records] Core library updates #49727
https://dart-review.googlesource.com/c/sdk/+/288903, https://dart-review.googlesource.com/c/sdk/+/295360
Record
base class with==
operator andhashCode
propertyFunction
class, and theidentical
functionrecord-related
wait
extensions onFuture
tuples:Add https://dart-review.googlesource.com/c/sdk/+/288903
The text was updated successfully, but these errors were encountered: