The Belt.Map structure uses an AVL tree internally which relies on sorting the keys. So it’s not possible for it to remember the insertion order.
One alternative is to use a list with Belt.List.getAssoc and Belt.List.setAssoc. These treat your list like a more basic kind of “map” which AFAIK will preserve insertion order. It’s probably similar to what you would do with using an array.
Note that the Belt maps use an AVL tree because it makes looking up items much more performant. Belt.Map.String.get will be more efficient than Belt.List.getAssoc. This is one of the tradeoffs you make when choosing a data structure.
If you need to preserve insertion order, then I assume you’re using your map with forEach or reduce to generate some other kind of value from it? In that case, a list (or an array) may be a better choice anyway.
Thx for the explaination.
Belt.List work but I would have preferred an easiest way to merge two occurence.
setAssoc force me to do a forEach on my “second” list to add item one by one to the “first” one.