I’d like to create a single function in Verse that handle a map
without worrying about the key or value type passed in the parameter..
My goal is to avoid writing multiple functions, such as AddAgentToMap, AddStringToMap, AddIntToMap, etc. Instead, I want a single function that accepts any key type and any value type (agent, string, int, float, logical, or even a class) and simply assigns the key-value pair to the map.
The idea would be something like this:
# Just the function example to be more direct
AddKeyToMap(Map : [K]V, Key : K, Value : V where K : AnyType, V : AnyType):[AnyType]AnyType =
var NewMap := Map
if:
not NewMap[Key]
set NewMap[Key] = Value
return NewMap
# Or within a class:
Map_Manager := class():
var Map : [AnyType]AnyType
AddKeyToMap(Key : AnyType, Value : AnyType):[AnyType]AnyType =
if:
not Map[Key]
set Map[Key] = Value
return Map
What I want to know:
Is there a way in Verse to declare any type parameters so that a function can work with any type of map?