Opa : howo to manipulate stringmap (and other map)

2019-02-25 17:37发布

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 ?

标签: string map opa
1条回答
甜甜的少女心
2楼-- · 2019-02-25 18:23

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)
查看更多
登录 后发表回答