sequency
sequency copied to clipboard
Support key param for sortBy and sortByDescending
Currently, it is possible to sort using the key of an item, but only through the Comparator
and ComparatorFactory
interfaces, for example:
https://github.com/winterbe/sequency/blob/7be941df1dce7c5ad50df60c1ddec72b46a54b54/test/sorted.test.ts#L67
https://github.com/winterbe/sequency/blob/7be941df1dce7c5ad50df60c1ddec72b46a54b54/test/sorted.test.ts#L89
https://github.com/winterbe/sequency/blob/7be941df1dce7c5ad50df60c1ddec72b46a54b54/test/sorted.test.ts#L108
https://github.com/winterbe/sequency/blob/7be941df1dce7c5ad50df60c1ddec72b46a54b54/test/sorted.test.ts#L135
The goal of this PR is to enable sorting by key directly on the Sequence
type, like:
sequenceOf(a4, a1, a3, a23)
.sortedBy("a")
sequenceOf(a4, a1, a3, a23)
.sortedByDescending("a")
Also, this PR exports the Comparator
and ComparatorFactory
types, so that they are added to the docs (which suppresses a couple warnings when generating them)
Hello @winterbe, I've been willing to do this for a long time. With this PR, the sorting functions should finally be consistent.