Proposal: Allow Func<T, T, bool>
where IEqualityComparer<T>
is expected
#8583
-
I saw a Api design in the runtime repo, where there are bunch of methods on this made me think, if it would be a good idea to allow public static bool Contains<T>(this ReadOnlySpan<T> span, T value, IEqualityComparer<T>? comparer = null); the following would be allowed: var c = [1, 2, 3, 4, 5];
c.Contains(5, (a, b) => a == b); (I know what this is a very simple example and can be solved differently, but I hope the idea is clear.) this would be implemented by emitting a anonymous class that implements the interface and uses the I am not sure, if I am the only one with this issue, but I guess, this would simplify a lot of codebases. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
See: #2517 |
Beta Was this translation helpful? Give feedback.
-
And #728 |
Beta Was this translation helpful? Give feedback.
-
That interface has |
Beta Was this translation helpful? Give feedback.
That interface has
Equals
andGetHashCode
, does the language have to run around and look for matching signatures? What if there are 2 methods with identical signatures? I think this is a bad idea.Declaring a class like
DelegateEqualityComparer<T>
is trivial (and it's probably already available in some general purpose helper Nuget).