Page 1 of 1
addMapEntry to index 0
Posted: 21 Dec 2017 23:32
by anuraag
Is it possible to addMapEntry to index 0 that is beginning of map?
Re: addMapEntry to index 0
Posted: 22 Dec 2017 02:39
by Desmanto
There is no direct function to do that. There is no also technical necessity to sort it too, since map values always work based on key-value mapping. So this is purely for aesthetic. I also wish to sort similar key together.
To insert at 0 index, the fastest way is using addAllMapEntries(). Create a temporary map of the key-value you wanna add, and add the original map to it.
Code: Select all
realmap = newMapFromValues(
"key1", "value1",
"key2", "value2");
addmap = newMapFromValues("key0", "value0"); // key value to be inserted
addAllMapEntries(addmap, realmap);
realmap = addmap;
removeVariable(addmap);
However it seems removeVariable(addmap) doesn't work properly in this 1.34.0 version. The addmap variable still shows up at debug dialog. Is it just me?
Sorting the map or inserting at index other than 0 can be done too, with extra effort. Even manual sorting is also possible, but more troublesome.
Re: addMapEntry to index 0
Posted: 22 Dec 2017 14:45
by bogdyro
This is the way to do it (include it in double quotes. Kind of annoying

removeVariable("addmap")
Re: addMapEntry to index 0
Posted: 22 Dec 2017 22:42
by Desmanto
Thanks for the tip.

I just use this removeVariable() the first time, even though i have seen it several times in others' flow. Double quote is fine, since sometimes we want to dynamically remove other variable.
I just proof the manual sorting is possible, and has made the flow to sort my glovar. Not a very important flow, but a nice exercise.
Re: addMapEntry to index 0
Posted: 22 Dec 2017 23:37
by anuraag
Thanks for tips.