Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Implement sortByComparison #112

Closed
aadamowski opened this Issue · 0 comments

2 participants

Aleksander Adamowski Caolan McMahon
Aleksander Adamowski

Currently, the sortBy method requires that an iterator is provided that returns a numerical value to be used for sorting elements according to numerical order.

This requirement cannot always be easily satisfied - the programmer is burdened with devising a proper numeric space which would be homomorphic to the sorted set with respect to its elements order.

I propose implementing additional sorting function, "sortByComparison", which in many cases would provide for cleaner and easier sorting.

The sortByComparison function should implement merge sort, possibly parallelized, and delegate element comparison to the iterator supplied to it.

Obviously, the iterator (or, for a better name, comparator) function should take not one, but two elements as its arguments and, similarly to its Java analog, should supply the comparison result to the callback function:

if (1st argument < 2nd argument) {
  callback(null, any integer < 0);
} else if (1st argument > 2nd argument) {
  callback(null, any integer  > 0);
} else if (1st argument == 2nd argument) {
  callback(null, 0);
} else {
  callback(new Error('this is impossible'), null);
}
Caolan McMahon caolan closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.