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

[API Proposal]: ToOrderedDictionary #110286

Open
rampaa opened this issue Nov 30, 2024 · 1 comment
Open

[API Proposal]: ToOrderedDictionary #110286

rampaa opened this issue Nov 30, 2024 · 1 comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Collections
Milestone

Comments

@rampaa
Copy link

rampaa commented Nov 30, 2024

Background and motivation

We have ToDictionary, ToFrozenDictionary, ToImmutableDictionaryand ToImmutableSortedDictionary extension method for other dictionary types already. Having similar extension methods for OrderedDictionary would allow us to use OrderedDictionary in places where we use other dictionary types with the same level of convenience.

API Proposal

public static OrderedDictionary<TKey, TElement> ToOrderedDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector) where TKey : notnull => ToOrderedDictionary(source, keySelector, elementSelector, null);
public static OrderedDictionary<TKey, TElement> ToOrderedDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey>? comparer) where TKey : notnull

API Usage

List<char> list = ['a', 'b', 'c'];
OrderedDictionary<char, double> orderedDictionary = list.ToOrderedDictionary(f => f, char.GetNumericValue);

Alternative Designs

No response

Risks

No response

@rampaa rampaa added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Nov 30, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Nov 30, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-collections
See info in area-owners.md if you want to be subscribed.

@eiriktsarpalis eiriktsarpalis removed the untriaged New issue has not been triaged by the area owner label Nov 30, 2024
@eiriktsarpalis eiriktsarpalis added this to the Future milestone Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Collections
Projects
None yet
Development

No branches or pull requests

2 participants