Blog Post: Taking Control of Map Sort Order in Elixir

OTP 26 was released and the Elixir 1.14.4 builds have been updated! Erlang OTP 26 changed how map keys are sorted, or not sorted actually. Check out this quick tip on how to customize IEx to always sort the map keys with your local development!

11 Likes

This is great, and I love that you shared your personal ~/.iex.exs, definitely gives me some ideas!

I’ll add that I’m also a big fan of defaulting to always printing charlists as lists of numbers:

IEx.configure(
  inspect: [
    charlists: :as_lists
  ]
)

This prevents the common confusion of wondering why the list of integers you were operating on suddenly renders as text.

5 Likes

Great post, is there a way to do this for tests too?

Currently I am doing something like

if :erlang.system_info(:otp_release) >= '26' do
  ...
else
 ...
end

But that’s ugly.

1 Like

Yes, good question.

I have unit tests failing on OPT 26 too. The failure is indirect, as I don’t do direct assertions on Map, but on json response.

Is there a way to deal with this, out of IEx.configure?