# A function that can handle any type of \`map\` key-value

**URL:** <https://forums.unrealengine.com/t/a-function-that-can-handle-any-type-of-map-key-value/2655205>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [September 9, 2025, 10:17pm UTC](https://forums.unrealengine.com/t/a-function-that-can-handle-any-type-of-map-key-value/2655205 "2025-09-09T22:17:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_RSK-7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@\_RSK-7](https://forums.unrealengine.com/u/_RSK-7)\
**Post date:** [September 9, 2025, 10:17pm UTC](https://forums.unrealengine.com/t/a-function-that-can-handle-any-type-of-map-key-value/2655205/1 "2025-09-09T22:17:42Z")

</div>

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:

```verse
# 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?

---

<div class="post-metadata">

**Author:** ![ReasonableTrout](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ReasonableTrout](https://forums.unrealengine.com/u/ReasonableTrout)\
**Post date:** [September 11, 2025, 3:37pm UTC](https://forums.unrealengine.com/t/a-function-that-can-handle-any-type-of-map-key-value/2655205/2 "2025-09-11T15:37:07Z")

</div>

I’m not quite sure why you need a function to add to a map, can’t you just do set Map[Key] = Value? But you can do it like this:

```verse
    AddKeyToMap(Map:[k]v, Key:k, Value:v where k:subtype(comparable), v:type): [k]v=
        var NewMap : [k]v = Map
        if. set NewMap[Key] = Value
        NewMap

```

Or as an extension method of map:

```verse
    (Map:[k]v where k:subtype(comparable), v:type).AddKey(Key:k, Value:v): [k]v=
        var NewMap : [k]v = Map
        if. set NewMap[Key] = Value
        NewMap

```

---

<div class="post-metadata">

**Author:** ![\_RSK-7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@\_RSK-7](https://forums.unrealengine.com/u/_RSK-7)\
**Post date:** [September 13, 2025, 4:41am UTC](https://forums.unrealengine.com/t/a-function-that-can-handle-any-type-of-map-key-value/2655205/3 "2025-09-13T04:41:06Z")

</div>

It’s not that I need it. It’s just that I like having functions for things that happen frequently, like assign a `map[Key]Value`.

Of course, I could do it the common way every time, like this:

```verse
var PlayersData : [player]Player_Data = map{}

AssignPlayerData(Player : player):void=
    if:
        not PlayersData[Player]
        set PlayersData[Player] = Player_Data{}

```

This is more of a curiosity and a possibility within Verse. I do a lot of things that might seem unnecessary when I’m programming. I just think that the more I can simplify my code, the better.

I found the extension method interesting. It might not be useful for all the map types I have, especially those with objects that need some initialization data.
