【问题标题】:Opa : howo to manipulate stringmap (and other map)Opa:如何操作字符串映射(和其他映射)
【发布时间】:2012-05-14 15:28:12
【问题描述】:

我想创建一个 Stringmap,在里面添加一些值,然后传递一些函数。我试过这个:

import stdlib.core.map

mymap = StringMap_empty



mymap["rabbit"] = 12


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

但是没有编译。我只能使用stringmap througt 数据库! (-> 数据库字符串映射(int) /myMap )

我的代码有什么问题?

【问题讨论】:

    标签: string map opa


    【解决方案1】:

    Opa 是一种函数式编程语言。您应该阅读此线程以获取更多信息: 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)
    

    【讨论】:

      猜你喜欢
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 2012-01-23
      • 1970-01-01
      • 2021-11-15
      • 2019-09-18
      • 2017-12-05
      • 1970-01-01
      相关资源
      最近更新 更多