diff options
author | Brett Snyder <bsnyder@digitalocean.com> | 2019-05-14 18:20:32 -0500 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2019-05-15 17:32:50 +0100 |
commit | af07c099e69e296aaeabeebcb3e0a304bcb24d1d (patch) | |
tree | a0b298ed1f2d227713d23c6643cb05a4bdf73273 /test | |
parent | 1c16eee098e36ed322450fe7c048701df466978e (diff) | |
download | gleam_stdlib-af07c099e69e296aaeabeebcb3e0a304bcb24d1d.tar.gz gleam_stdlib-af07c099e69e296aaeabeebcb3e0a304bcb24d1d.zip |
map_dict:fold
Diffstat (limited to 'test')
-rw-r--r-- | test/map_dict_test.gleam | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/map_dict_test.gleam b/test/map_dict_test.gleam index 551a333..6ff9133 100644 --- a/test/map_dict_test.gleam +++ b/test/map_dict_test.gleam @@ -1,5 +1,6 @@ import expect import map_dict +import str pub fn from_list_test() { [ @@ -201,3 +202,32 @@ pub fn update_test() { |> map_dict:update(_, "z", inc_or_zero) |> expect:equal(_, map_dict:from_list([{"a", 0}, {"b", 1}, {"c", 2}, {"z", 0}])) } + +pub fn fold_test() { + let dict = map_dict:from_list([ + {"a", 0}, + {"b", 1}, + {"c", 2}, + {"d", 3}, + ]) + + let add = fn(_, v, acc) { + v + acc + } + + dict + |> map_dict:fold(_, 0, add) + |> expect:equal(_, 6) + + let concat = fn(k, _, acc) { + str:append(acc, k) + } + + dict + |> map_dict:fold(_, "", concat) + |> expect:equal(_, "abcd") + + map_dict:from_list([]) + |> map_dict:fold(_, 0, add) + |> expect:equal(_, 0) +} |