brainlid

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

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

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

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.

ColmB

ColmB

Yes we ended up at that conclusion ourselves. In the end there weren’t too many places where we had inspected a whole map into an error message. Currently fighting with Jason encoded AWS Publish data which again was tested against the whole expected message and which Jason is now randomly changing the order of. Nothing is ever simple!

Where Next?

Popular in Blog Posts Top

danschultzer
How to set up the Content Security Policy header with Phoenix LiveView and support inline styles and scripts with CSP nonces.
New
MarcinKasprowicz
What I genuinely value at my workplace is that I can easily explore new languages through internal mobility. Throughout my career within ...
#js
New
jordiee
https://medium.com/@jpiepkow/team-based-login-with-accesspass-be236d4bd7dd
New
brainlid
Elixir has a built-in Zip library that comes with OTP. This post explores how to use the zip module and asks the important question: “Is ...
New
AstonJ
Elixir Blog Posts How to use this section You can post links to your blog posts either in one of the Official Blog Posts threads, or, vi...
New
zacksiri
In December of 2023 we came to the realization that we needed to build our own image server. After hitting a few snags we decided that it...
New
rms.mrcs
Hi, everyone! In this article I describe how I created a simple metrics engine that can list to Hackney metric updates and send this data...
New
DevotionGeo
There are 3 main formatters for Erlang which you can use from the command-line, rebar3_format, Steamroller elmfmt. Visual Studio Cod...
New
ragamuf
A little halloween hocus-pocus on the value proposition of having a reliable test suite in place. You are not scared, are you?
New
brainlid
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...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
siddhant3030
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

We're in Beta

About us Mission Statement