Why does Enumerable.SequenceEqual take its comparer as an IEqualityComparer? The algorithm seems to make no use of GetHashCode. Why does it not instead take a Func<TSource, TSource, bool>
predicate, similar to how First takes a Func<TSource, bool>
?
I am tempted to say "because".
If you look around at other similar methods (like Enumerable.Distinct) they also take an IEqualityComparer
in the overload.
Also, an IEqualityComparer
is the "correct" way to check if objects are equal. A Func<TSource, TSource, bool>
would not neccessarily check for equality, it would check if the objects are similar enough for your specific usage at this moment in time.
Luckily it is easy enough to make your own extension method. For instance does MoreLinq have a implementation of DistinctBy
that you can look at.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With