Skip to content
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

Map<TKey, TValue> should inherit from Iterable<MapEntry<TKey, TValue>> #52435

Closed
ahmednfwela opened this issue May 18, 2023 · 5 comments
Closed
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue

Comments

@ahmednfwela
Copy link

Moved from dart-lang/language#3081

currently to iterate over a Map, you need to access the entries property, but you can't iterate over the map itself

this makes representing a union of Map | List a chore, since they have no common denominator, thus requiring changing the type to dynamic

@lrhn
Copy link
Member

lrhn commented May 18, 2023

A map is not, will not, and cannot be an Iterable.

While some members can co-exist (Map has containsKey/containsValue and Iterable has contains),
the method forEach has incompatible types between the two interfaces.

So, it cannot be.

@lrhn lrhn closed this as completed May 18, 2023
@lrhn lrhn added the closed-not-planned Closed as we don't intend to take action on the reported issue label May 18, 2023
@ahmednfwela
Copy link
Author

ahmednfwela commented May 18, 2023

@lrhn why not ? C# has IDicitionary inheriting from IEnumerable just fine

methods that can't coexist in Map can be marked deprecated and removed at a later release as a breaking change

@lrhn
Copy link
Member

lrhn commented May 18, 2023

In C#, a class can have two members with the same name, but different signatures.
I'm Dart that's not possible.
The forEach of the Map interface makes it impossible to implement Iterable too.

@ahmednfwela
Copy link
Author

oh I see, so it's just blocked by dart-lang/language#1122

@lrhn
Copy link
Member

lrhn commented May 23, 2023

Yes, "just" blocked on that. 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue
Projects
None yet
Development

No branches or pull requests

2 participants