Hey guys, I'm studying Elixir, and noticing that as of 0.12.5 Enum.sort/2 isn't a stable implementation of Merge Sort.
Yet, as mentioned it doesn't preserve the order of the items.
I believe that this is a property desired in a core sorting method so that it can be used to implement multiple-pass sorts.
By multiple-pass sort what I mean is:
sorted_info = get_student_info |> sort_by_student_number |> sort_by_first_name |> sort_by_last_name
If the implementation of sort isn't stable, I can't guarantee that after I sort them by student number, students with the same name and last name will remain in student number order.
Here are snipets of code that show it is *almost* stable, but elements of the same "weight" are in reverse (?)
Example code:
iex(1)> Enum.sort ["some","kind","of","monster"], &(String.length(&1) > String.length(&2))
["monster", "kind", "some", "of"]
iex(2)> Enum.sort ["some","kind","of","monster"], &(String.length(&1) < String.length(&2))
["of", "kind", "some", "monster"]
iex(3)> Enum.sort ["once","upon","a","time"], &(String.length(&1) > String.length(&2))
["time", "upon", "once", "a"]
iex(4)> Enum.sort ["once","upon","a","time"], &(String.length(&1) < String.length(&2))
["a", "time", "upon", "once"]
iex(5)> Enum.sort ["upon","once","a","time"], &(String.length(&1) < String.length(&2))
["a", "time", "once", "upon"]
iex(6)> Enum.sort ["upon","once","a","time"], &(String.length(&1) > String.length(&2))
["time", "once", "upon", "a"]
I performed a quick search on the github repo and found nothing mentioning the stability of it. And even on this list I wasn't able to find the reasoning behind the current implementation. Needless to say "stabl" doesn't return anything on the documentation I linked above.
What are the considerations that made it not be a stable sort? Or is this a bug that merits a github issue?