brainlid
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!
Most Liked
christhekeele
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.
brainlid
While this isn’t the answer you’re looking for, I find it’s best for tests to not count on the order of map. You can assert a match, for instance, where the fields in the map you care about for the test match the output.
These types of tests tend to hold up better as returned maps evolve with more data being added but aren’t relevant for the test. It avoids causing unrelated failures.
Hermanverschooten
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.
Popular in Blog Posts
Other popular topics
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
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









