Skip to content

Port pairs extension from dart-archive/collection#289 - #979

Open
samlythemanly wants to merge 1 commit into
dart-lang:mainfrom
samlythemanly:ext-pairs
Open

Port pairs extension from dart-archive/collection#289#979
samlythemanly wants to merge 1 commit into
dart-lang:mainfrom
samlythemanly:ext-pairs

Conversation

@samlythemanly

Copy link
Copy Markdown

This ports the pairs extension 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.


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

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.

@samlythemanly
samlythemanly requested a review from a team as a code owner July 17, 2026 02:19
@mosuem

mosuem commented Jul 27, 2026

Copy link
Copy Markdown
Member

@dart-lang/dart-core-packages-team any feedback here?

@natebosch
natebosch requested a review from lrhn July 29, 2026 00:09

@lrhn lrhn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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].

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)]));
});
});
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little sparsely tested.
Try with maps that don't use normal equality.
Maybe an identity map with two equal-but-district keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants