Closed janosroden closed 2 years ago
I hadn't considered DateTime
, that would be a good addition to the pre-built comparers. The choice to use a custom EqualityComparer
rather than to just use Comparable
was intentional, though it would be good to have some built-in interop added.
The purpose of using the class-based EqualityComparer
rather than the interface-based Comparer
is so that equality, hashing, and sorting can be supported even by types that don't implement Comparable
, which is particularly important when dealing with a type that the user doesn't have the ability to change the type in order to inherit it (such as a type coming from a third-party package). Another reason is for convenience - if you only need to sort in one place, it is easier to specify 1-3 lambdas rather than implementing Comparable
on the type itself.
@andrewackerman Awesome package, dart standard library missing the lot of stuff from .NET!
I just noticed the orderBy doesn't support DateTime. I looked the code and I saw you picked several 'scalar' types to support. I guess you missed the Comparable type which is implemented by these types (including DateTime) except Iterable.
Of course
tryForType
andregisterEqualityComparer
should search slightly different but I think it would worth the effort. ActuallyEqualityComparer
is a little bit unnecessary becauseComparable<T>
gives interface for both equality check and sorting; Object offers a way to overridehashCode
. Anybody who wants to change the behaviour just need to wrap that special handled type with custom overrides.I'm happy to create a PR if you agree with the changes and have time to review/publish.