如何在Elm中创建Dict进行测试?

时间:2015-12-08 11:17:53

标签: elm

要在elm中创建列表,您可以执行以下操作:

list = ["test","test2"]

但是如何为测试目的创建Dict?

我已阅读Dict - core 3.0.0

1 个答案:

答案 0 :(得分:11)

let dict = Dict.fromList [("key1", "value1"), ("key2", "value2")]

要插入元素:let dict' = Dict.insert "key3" "value3" dict

要查找元素:

case Dict.get "key1" dict of
  Just value -> ... -- do something with value
  Nothing -> ... -- no such value in dict