Opa : howo to manipulate stringmap (and other map)

耗尽温柔 提交于 2019-12-02 04:36:36

问题


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)


来源:https://stackoverflow.com/questions/10586367/opa-howo-to-manipulate-stringmap-and-other-map

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!