-
Notifications
You must be signed in to change notification settings - Fork 1
explore a slightly more generic solution #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
that's a really neat idea, and we should do that! (but i think we should also add a single comparator function) |
Eh, I'm open to having both, but the difference in ergonomics here is really really small to me. |
I'd still want Sorting is used a lot. An unanswered question here is how efficient the generalization would be compared to a hand-written |
A function compareLexicographic(itemComparator, getIter = x => x[Symbol.iterator]()) {
const NIL = {};
return function (as, bs) {
for (let [a, b] of Iterator.zip([getIter(as), getIter(bs)], { mode: 'longest', padding: [NIL, NIL] })) {
if (a === NIL) return -1;
if (b === NIL) return 1;
let itemResult = itemComparator(a, b);
if (itemResult !== 0) return itemResult;
}
return 0;
}
} which you'd use here as And at that point I don't think you can reasonably ask users to come up with that on their own. |
@waldemarhorwat If there's a performance difference, I would find that more compelling than simply an ergonomic difference. But as with the object property counting proposal, I have a lot of faith in engines to do some clever pattern recognition. |
More faith in the engines than the engines have themselves, I think. |
Long, long ago, I was very interested in a array.sort(by(({x, y}) => (x**2 + y**2)**0.5)) |
Uh oh!
There was an error while loading. Please reload this page.
Instead of providing just a specialised function that would be used like
it would be similarly ergonomic and more generally applicable to do something like
assuming we had (roughly)
and also (roughly)
The text was updated successfully, but these errors were encountered: