Here’s a small code snippet that may clarify how to use some of the DA.Next.Map
functions:
module Main where
import Daml.Script
import qualified DA.Next.Map as Map
setup : Script ()
setup = script do
let map1 = Map.fromList [(1, "a"), (2, "b")]
let map2 = Map.fromList [(2, "c"), (3, "d")]
assert (
Map.insert 5 "hello!" map1
==
Map.fromList [(1, "a"), (2, "b"), (5, "hello!")]
)
assert (
Map.insert 1 "changed!" map1
==
Map.fromList [(1, "changed!"), (2, "b")]
)
assert (
Map.delete 2 map1
==
Map.fromList [(1, "a")]
)
assert (
Map.union map1 map2
==
Map.fromList [(1, "a"), (2, "b"), (3, "d")]
)
assert (
Map.merge (\k v -> Some $ "from 1: " <> v)
(\k v -> Some $ "from 2: " <> v)
(\k v1 v2 -> Some $ "from both: " <> v1 <> ", " <> v2)
map1
map2
==
Map.fromList [(1, "from 1: a"),
(2, "from both: b, c"),
(3, "from 2: d")]
)