Port pairs extension from dart-archive/collection#289 - #979
Conversation
|
@dart-lang/dart-core-packages-team any feedback here? |
lrhn
left a comment
There was a problem hiding this comment.
It's a perfectly usable implementation.
I'm still not sold on having the pairs getter, but it shouldn't hurt (other than wastefully allocating the MapEntry objects).
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| extension MapExtensions<K, V> on Map<K, V> { | ||
| /// Like [Map.entries], but returns each entry as a record instead of a [MapEntry]. |
There was a problem hiding this comment.
Docs should say what it is from scratch, not start out relative to something else.
Iterables don't "return" anything.
Consider:
/// The key and value pairs of this map. /// /// Contains `(key, value)` for each key `key` /// and it's associated value, in key iteration /// order.
Should probably also document that contains uses equality of record pairs, it does not use the map's lookup, and it's not efficient.
(The .map iterable should have efficient length, but not much else.)
| equals(const [(1, 2), (3, 4), (5, 6)])); | ||
| }); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
A little sparsely tested.
Try with maps that don't use normal equality.
Maybe an identity map with two equal-but-district keys.
This ports the
pairsextension from dart-archive/collection#289.The original implementation was approved but got derailed by rollup attempts that included a major version bump and breaking changes (dart-archive/collection#284 and #859). Those PRs have been in limbo for years and are unlikely to ever be merged.
Contribution guidelines:
dart format.Many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.
Note: The Dart team is trialing Gemini Code Assist. Don't take its comments as final Dart team feedback. Use the suggestions if they're helpful; otherwise, wait for a human reviewer.