-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Align API surface of immutable collections and their corresponding builder types #822
Comments
Thank you for the proposal @reflectronic. I think the changes make sense, given that we are committed to API parity between immutable types and their builder counterparts. Would you be able to make a couple of updates to the proposal before I mark this ready for review?
Thanks! |
Thanks for taking a look @eiriktsarpalis. I made the requested changes and additionally removed a couple more APIs from the proposal which didn't make sense. |
A few follow-up remarks:
|
Sorry for taking a while to respond. I addressed the comments, except for the |
Yeah I think that's pretty reasonable. We could reconsider at a future iteration. |
public class ImmutableSortedDictionary<TKey, TValue>.Builder
{
public void SetItems(IEnumerable<KeyValuePair<TKey,TValue>> items);
} This is not needed for a mutable collections, using the indexer should be sufficient. |
Done. Should be ready for review now, I think. |
namespace System.Collections.Immutable
{
public struct ImmutableArray<T>
{
public ImmutableArray<T> AddRange(params T[] items);
public ImmutableArray<T> AddRange(T[] items, int length);
public ImmutableArray<T> AddRange<TDerived>(TDerived[] items) where TDerived : T;
public ImmutableArray<T> AddRange(ImmutableArray<T> items, int length);
public ImmutableArray<T> AddRange<TDerived>(ImmutableArray<TDerived> items) where TDerived : T;
public partial class Builder
{
public void CopyTo(T[] destination);
public void CopyTo(int sourceIndex, T[] destination, int destinationIndex, int length);
public int IndexOf(T item, int startIndex, IEqualityComparer<T>? equalityComparer);
public void InsertRange(int index, IEnumerable<T> items);
public void InsertRange(int index, ImmutableArray<T> items);
public void Replace(T oldValue, T newValue);
public void Replace(T oldValue, T newValue, IEqualityComparer<T>? equalityComparer);
public void Remove(T item, IEqualityComparer<T>? equalityComparer);
public void RemoveRange(int index, int length);
public void RemoveRange(IEnumerable<T> items);
public void RemoveRange(IEnumerable<T> items, IEqualityComparer<T>? equalityComparer);
public void RemoveAll(Predicate<T> match);
}
}
public partial class ImmutableList<T>
{
public partial class Builder
{
public void Remove(T value, IEqualityComparer<T>? equalityComparer);
public void RemoveRange(int index, int count);
public void RemoveRange(IEnumerable<T> items);
public void RemoveRange(IEnumerable<T> items, IEqualityComparer<T>? equalityComparer);
public void Replace(T oldValue, T newValue);
public void Replace(T oldValue, T newValue, IEqualityComparer<T>? equalityComparer);
}
}
public partial class ImmutableSortedSet<T>
{
public partial class Builder
{
public int IndexOf(T item);
}
}
} |
Is this ready for 7.0? |
This is not on our radar for .NET 7 at the moment, but we would consider a community contribution that provides an implementation of the approved API. |
Hi @eiriktsarpalis I have created the PR for this issue, could you help me review it 😀 |
Rationale
There is a slight mismatch between the API surface of each immutable collection type and its corresponding builder. To improve the usability of these APIs, we should consider more closely aligning the APIs exposed in each immutable collection type and its corresponding builder. (I automatically generated this list, but of course some differences should be left be; for example,
Union
vsUnionWith
, or equality operators, so I left them out.)Related to: #31242 #28160 #31208 Probably some others
Proposed API
ImmutableArray
ImmutableList
ImmutableSortedSet
ImmutableSortedDictionary<TKey, TValue>
has a memberSetItems
which isn't available on the builder. However, because one can just use the indexer to do the same thing, it isn't really appropriate.The text was updated successfully, but these errors were encountered: