eksperimental
Natural Sorting algorithms
Hi,
we are trying to sort things naturally in ExDoc.
Can anybody recommend a natural sorting algorithm implementation in Elixir?
I have a a few but I am looking for options,
Thank you.
Most Liked
mudasobwa
Creator of Cure
FWIW, I have proposed the custom optimized sorter: Sort items "naturally" in menu, summary, function list, etc. · Issue #1440 · elixir-lang/ex_doc · GitHub
4
adkron
Sebb
How do you define “natural”?
Things that come to mind:
- ignore case
- ignore diacritics
2 < 10
1
Last Post!
sabiwara
Elixir Core Team
Just for reference, here is the same approach with a custom comparator. I didn’t bench these but since it doesn’t build tuples it is probably faster:
defmodule Natural do
def natural_sort(enumerable) do
Enum.sort(enumerable, __MODULE__)
end
def compare(x, y) do
case do_compare(String.upcase(x), String.upcase(y)) do
:eq -> do_compare(x, y)
lt_or_gt -> lt_or_gt
end
end
defp do_compare(x, x), do: :eq
defp do_compare(x, y) when x > y, do: :gt
defp do_compare(_, _), do: :lt
end
1
Popular in Questions
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Other popular topics
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









