elm / core

Elm's core libraries
http://package.elm-lang.org/packages/elm/core/latest
BSD 3-Clause "New" or "Revised" License
2.8k stars 359 forks source link

Case sensitivity when sorting strings is difficult to deal with #1140

Open KasMA1990 opened 1 year ago

KasMA1990 commented 1 year ago

We have many places in our code base where we need to sort strings to be displayed in the UI, which we normally do by calling either compare, List.sort or List.sortBy. All of these functions will sort strings in a case sensitive manner though, which is rarely what we want. That is, sorting a list of strings ala [ "a", "c", "B" ] will give [ "B", "a", "c" ] when we really want [ "a", "B", "c" ].

The simplest fix for this is to remember to always call String.toLower in the appropriate places before sorting, but this has proven untenable in the long run for our big code base with many developers on it. We're now starting to ban calling compare directly using elm-review and only allowing wrappers which force you to explicitly choose the ordering you want (e.g. compareStringsIgnoreCasing and compareStringsWithCasing). This works, but also has downsides, like how we can't have those wrappers take comparable arguments, but only String, so now must tighten our types in places that could previously use comparable types to be String for example.

All in all, the current API doesn't feel like it has any good solutions for this.

github-actions[bot] commented 1 year ago

Thanks for reporting this! To set expectations:

Finally, please be patient with the core team. They are trying their best with limited resources.