如何在 Elm 中创建一个用于测试的字典?
How to create a Dict in Elm for testing?
要在 elm 中创建列表,您可以执行以下操作:
list = ["test","test2"]
但是我如何创建用于测试目的的字典?
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
要在 elm 中创建列表,您可以执行以下操作:
list = ["test","test2"]
但是我如何创建用于测试目的的字典?
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