Opa : howo to manipulate stringmap (and other map)

219 Views Asked by At

I want to create a Stringmap, add some values inside, and pass it some function. I've tried this :

import stdlib.core.map

mymap = StringMap_empty



mymap["rabbit"] = 12


function addmap(map)
{
        map["rabbit"] = 24
}

But nothing compile. I can only use stringmap througt database ! (-> database stringmap(int) /myMap )

What's wrong with my code ?

1

There are 1 best solutions below

0
On

Opa is a functional programming language. You should read this thread for more information: Opa: Iterating through stringmap and forming a new string based on it

mymap = StringMap.empty

mymap = StringMap.add("rabbit", 12, mymap)
// you can't just write StringMap.add("rabbit", 12, mymap)
// because values are by default not mutable
// the function returns the map with the new element added


function addmap(map)
{
        StringMap.add("rabbit", 24, map)
}

mymap = addmap(mymap)