Page MenuHomeFeedback Tracker

Scripting Feature Request: Extend HashMap getOrDefault command with set default parameter
Closed, ResolvedPublic

Description

This is a request for a setDefault bool parameter to be added to the getOrDefault command. This parameter (when set to true, default: false) would make the command work similarly to Python's dictionary.setdefault(keyname, value) method. That is, if the given key does not exist in the hash map, then the default value is still returned but the key is also set to the default value in the hash map.

This would allow the following code (_faction is some faction class name and _vehicle is some vehicle class name):

private _hashMap = createHashMap;
private _list = _hashMap get _faction;

if (isNil "_list") then {
    _list = [];
    _hashMap set [_faction, _list];
};

_list pushBack _vehicle;

to be simplified as:

private _hashMap = createHashMap;
private _list = _hashMap getOrDefault [_faction, [], true]; // <- set default parameter
_list pushBack _vehicle;

The new syntax for the getOrDefault command would look like: hashMap getOrDefault [key, defaultValue, setDefault]

  • hashMap <HashMap>
  • key <HashMapKey>
  • defaultValue <ANY> (optional, default: nil)
  • setDefault <BOOL> (optional, default false)

Details

Severity
Feature
Resolution
Open
Reproducibility
N/A
Operating System
Windows 10 x64
Category
Scripting

Event Timeline

2.04 rev 147451

dedmen closed this task as Resolved.Mar 16 2021, 10:49 AM
dedmen claimed this task.