Page MenuHomeFeedback Tracker

ARRAY createHashMapFromArray CODE
New, NormalPublic


I propose to add createHashMapFromArray command variant to take CODE as right operand, with left ARRAY keys passed as arguments into the CODE. The main purpose is shortening and beautifying hashmap creation, with a bit of performance gain.

Syntax: ARRAY createHashMapFromArray CODE

I found myself creating hashmap from single array of keys as base using createHashMapFromArray very often like this:

private _sides = [blufor, opfor, independent, civilian];
_sides createHashMapFromArray (_sides apply {
    private _side = _x;
    {side group _x == _side} count allUnits;

with such new command variant you would be able to write it shorter as

fnc_count_units_of_side = {
    {side group _x == _this} count allUnits;
[blufor, opfor, independent, civilian] createHashMapFromArray fnc_count_units_of_side;

or even just

[blufor, opfor, independent, civilian] createHashMapFromArray {
    {side group _x == _this} count allUnits;

I think that passing ARRAY elements into CODE as _this instead of _x is a better choice. This will let you feed existing callable functions into it (including BIS_fnc_ stuff) without having to wrap it into additional scope like {_x call BIS_fnc_something}.


Operating System
Windows 10 x64
Additional Information

Alternative name ideas:
ARRAY createHashMapFromKeys CODE
ARRAY createHashMapFromCode CODE
ARRAY createHashMapFromCall CODE
ARRAY createHashMapFromFunction CODE

Event Timeline

SaMatra created this task.Feb 16 2023, 11:02 AM
RSandiford added a subscriber: RSandiford.EditedWed, Mar 1, 12:56 PM

Why not just make your own?

SaMatra_fnc_createHashMapFromCode = {
	params ["_arr", "_code"];
	_hashMap = createHashMap;
		_hashMap set [_x, _x call _code];			
	} forEach _arr;


    [blufor, opfor, independent, civilian],
    { {side group _x == _this} count allUnits; };
] call SaMatra_fnc_createHashMapFromCode;

Yes its all already possible, its a question of convenience of doing it with a single command.

dedmen set Ref Ticket to AIII-55577.Wed, Mar 1, 1:55 PM