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
Add ascendNatural and descendNatural functions #3442
Conversation
Coverage> ramda@0.29.1 coverage:summary
> BABEL_ENV=cjs nyc --reporter=text-summary mocha -- --reporter=min --require @babel/register
�[2J�[1;3H
1188 passing (907ms)
=============================== Coverage summary ===============================
Statements : 94.03% ( 2474/2631 )
Branches : 85.73% ( 967/1128 )
Functions : 93.24% ( 552/592 )
Lines : 94.31% ( 2320/2460 )
================================================================================ |
Coverage> ramda@0.29.1 coverage:summary
> BABEL_ENV=cjs nyc --reporter=text-summary mocha -- --reporter=min --require @babel/register
�[2J�[1;3H
1188 passing (902ms)
=============================== Coverage summary ===============================
Statements : 94.03% ( 2474/2631 )
Branches : 85.73% ( 967/1128 )
Functions : 93.24% ( 552/592 )
Lines : 94.31% ( 2320/2460 )
================================================================================ |
This seems a useful and well-written PR. These sound like useful additions. Do others have objections? |
Feels a bit niche to me? Considering we can write |
Thanks for the feedback. Before implementing I was looking up what natural sort order is supposed to do, and by definition in Wikipedia it is
So for the most intuitive usage (I thought) I had set |
Just to revive this proposal, I'd like to add my opinion here too. Admittedly it's "a bit niche", it fixes sorting text with Ramda. Which is great because If Instead of introducing those two new comparator functions, can you imagine, to change the implementation of However, the problem is the customization. To sort according to the browser or Node.js locale (language) might be not target-oriented in most cases. I'd suggest to allow to pass at least the language to So that in this case const
collectionItemComparator = ascendNatural(identity);
sort(collectionItemComparator('de'), x) Or should the language come as first argument instead? I.e. is it the least changing argument? |
Ya and niche was not the right word, ramda could have a better story for sorting by string. I like language first. Should this be called @sebbayer sorry for the slow review! Could you add |
…l.Collator and better examples
Coverage Summary> ramda@0.30.0 coverage:summary
> BABEL_ENV=cjs nyc --reporter=text-summary mocha -- --reporter=min --require @babel/register
�[2J�[1;3H
1190 passing (1s)
=============================== Coverage summary ===============================
Statements : 94.04% ( 2477/2634 )
Branches : 85.73% ( 967/1128 )
Functions : 93.25% ( 553/593 )
Lines : 94.32% ( 2323/2463 )
================================================================================ |
Sorry for the late reply, I am glad there is still interest in the topic. @semmel I added the language parameter first as you suggested. I hope I got the function signature right. I updated the functions with better examples and tests have also been updated. To my surprise the locale based sorting result was pretty much the same in English, German and French, but for example Swedish has differences. My use case so far was only numeric string sorting. I left the I still like the |
There is no built-in way to do natural sorting on strings, therefore I propose
ascendNatural
anddescendNatural
to add this functionality vialocaleCompare
. Use exactly like you would withascend
anddescend
. The implementation is also very similar.