I have an Immutable.Map (plannedLoads) and I want to move all entries where val.get('loads_client_id') === ClientId.CLIENT_SLOT to the end of the map, preserving the order of all other entries.
Currently, I try this approach: ` let plannedLoads = !unplannedMode ? rootLoads.get(PLANNED_LOADS) || defaultMap : defaultMap;
let plannedLoadsSlot = plannedLoads.filter(
val => val.get('loads_client_id') === ClientId.CLIENT_SLOT
);
plannedLoads = plannedLoads.filter(
val => val.get('loads_client_id') !== ClientId.CLIENT_SLOT
);
plannedLoads = plannedLoads.concat(plannedLoadsSlot);`
But this does not work as expected. But this does not work as expected — instead of moving these entries to the end, the map returns them back to their original positions.. Also, I want to avoid converting the map to arrays or lists to save memory.
How can I reorder entries in an Immutable.js Map to move certain entries to the end without converting to other data structures?
Answer
In short, you can't.
From docs:
Immutable Map is an unordered Collection...
Iteration order of a Map is undefined...
Source: