kokolegorille

kokolegorille

In Elixir, the order of the keys is persisted if You have less than about 135 keys. I do not remember the exact number… nor where I learned that :slight_smile:

0
Post #21
Sebb

Sebb

:face_with_monocle:

1
Post #22
kokolegorille

kokolegorille

Oh, thanks :slight_smile:

0
Post #23
Sebb

Sebb

intereseting fact, but …

citation needed.

0
Post #24
msimonborg

msimonborg

Hmm :sweat_smile: I only “learned” by playing around in the repl. High probability that I’m wrong :slightly_smiling_face:

1
Post #25
kokolegorille

kokolegorille

I checked, as I do remember it was my first question on the Elixir forum.

32 is the number I had in mind at that time, I guess I inflated the number a little bit :slight_smile:

No, it’s me :slight_smile:

2
Post #26
BartOtten

BartOtten

Final and conclusive solution; always deleting the 1st pair:

new_map = 
  %{“name” => “foo”, “address”=> “bar”}
  |> Enum.into(%{}, fn
    {“name”, v} -> {“1st”, v}
    other -> other
  end)
  |> Map.drop([“1st”])

ps. try this at home but never at work.

2
Post #27
BartOtten

BartOtten

At the moment of writing it’s true but one should not rely on it. So we may as well forget it as it’s an implementation detail that might change.

Still a fun Trivia fact to know though…for as long as it lasts :slight_smile:

3
Post #28
msimonborg

msimonborg

If it wasn’t piping a list into a Map function this would be the definitive way to drop the 1st pair of a map :joy:

0
Post #29
sabiwara

sabiwara

Elixir Core Team

If performance is a concern and we don’t want to create a full map from scratch, maybe we could do something like (disclaimer: I didn’t benchmark):

{first_key, _, _} = map |> :maps.iterator() |> :maps.next()
Map.delete(map, first_key)

(“first_key” in the sense of whatever keys comes out first :slightly_smiling_face:)

1
Post #30