Opa : howo to manipulate stringmap (and other map)

2019-02-25 18:19发布

问题:

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:

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)


标签: string map opa