Skip to content
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

Support for compareFunction for sorted method #3770

Open
andrei-tofan opened this issue May 31, 2021 · 6 comments
Open

Support for compareFunction for sorted method #3770

andrei-tofan opened this issue May 31, 2021 · 6 comments

Comments

@andrei-tofan
Copy link

andrei-tofan commented May 31, 2021

In the latest version of RealmSwift is possible to provide a compare function to the sorted method, this is very useful for more complex sorting and locale-aware sorting (sorting edge case - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#using_options).

Is there a way to supply a compare function to the sorted method? Didn't find an option in the documentation.

@kneth
Copy link
Contributor

kneth commented Jun 2, 2021

@andrei-tofan The short answer is no.

The reason why we haven't added the functionality so far is that we fear that the many callbacks to JavaScript will degenerate the performance to an unacceptable level.

@jaltin
Copy link

jaltin commented Jun 2, 2021

Hi @kneth. Your point about performance concerns is understandable.

Is there another way this could be solved? For example by passing a sort priority string into realm when opening the DB (or at any point that is more suitable), so you could do the sorting natively for performance reasons? This would make it super flexible for us as developers to control the sorting and be sure it behaves the same as in JS.

For example, a sort string could look like this for swedish:

'­� _-,;:!¡?¿.·'"«»()[]{}§¶@*/&#%`´^¯¨¸°©®+±÷×<=>¬|¦~¤¢$£¥01¹½¼2²3³¾456789aAbBcCçÇdDðÐeEéÉèÈêÊëËfFgGhHiIíÍìÌîÎïÏjJkKlLmMnNñÑoOºóÓòÒôÔöÖõÕøØpPqQrRsSßtTuUúÚùÙûÛüÜvVwWxXyYýÝÿzZþÞµªáÁàÀâÂåÅäÄãÃæÆ',

and like this for english

'� _-,;:!?.'"()[]{}@*/&#%`^+<=>|~$0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ',

@jaltin
Copy link

jaltin commented Jun 9, 2021

Hi again @kneth. What do you think about my suggestion from 7 days ago? Thx!

@kneth
Copy link
Contributor

kneth commented Jul 12, 2021

@jaltin

A generic solution for sorting isn't trivial to implement as outlined in realm/realm-core#2573. In particular, Android doesn't have support for ICU.

Realm Core doesn't provide a callback mechanism, but it might be worth considering instead of keep waiting for Android NDK to provide the optimal solution.

@jaltin
Copy link

jaltin commented Dec 15, 2021

Hi @kneth,

Pinging this issue to see if you have the possibility to look into this further?

Thx!

@kneth
Copy link
Contributor

kneth commented Dec 22, 2021

@jaltin We haven't priorities it before but I will bring it up after the holidays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants