Default Map Value Topic is solved

Propose new features and changes
User avatar
Posts: 108
Joined: 29 Nov 2020, 09:06

Default Map Value

Post by Coiler » 08 Apr 2021, 18:43

Last wish for a while, I promise. Something I would really like to see added to maps is a default or fallback value on key->value request:

Code: Select all

	myval := mymap[mykey, my_default_value]
	myval := mymap.Find(mykey, my_default_value)
When the key is not found, it would return the default value without changing the map.

Currently, there is no simple way to ask the map if it has a value, then get that value, without searching for that value twice.

Posts: 246
Joined: 22 Feb 2016, 10:49

Re: Default Map Value

Post by braunbaer » 19 Apr 2021, 07:21

When the key is not found, it will yield the empty string.

Code: Select all

myval := mymap[mykey], !myval? myval:=my_default_value

Posts: 7420
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Default Map Value  Topic is solved

Post by lexikos » 20 Apr 2021, 21:31

@braunbaer This wish is regarding the Map type in AutoHotkey v2. It does not yield an empty string by default.

v2.0-a132 implements mymap.Default := my_default_value and mymap.Get(mykey, my_default_value).
lexikos wrote:
19 Apr 2021, 04:44
Added Map.Prototype.Get(Key, Default).
Added optional Default property for Map to return when key is not found.

Post Reply

Return to “Wish List”