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 /src | |
parent | 1c16eee098e36ed322450fe7c048701df466978e (diff) | |
download | gleam_stdlib-af07c099e69e296aaeabeebcb3e0a304bcb24d1d.tar.gz gleam_stdlib-af07c099e69e296aaeabeebcb3e0a304bcb24d1d.zip |
map_dict:fold
Diffstat (limited to 'src')
-rw-r--r-- | src/map_dict.gleam | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/map_dict.gleam b/src/map_dict.gleam index 6033866..c25378f 100644 --- a/src/map_dict.gleam +++ b/src/map_dict.gleam @@ -86,3 +86,11 @@ pub fn update(dict, key, f) { | Error(_) -> put(dict, key, f(Error(NotFound))) } } + +pub fn fold(dict, acc, f) { + let kvs = to_list(dict) + case kvs { + | [] -> acc + | [{k, v} | _] -> fold(delete(dict, k), f(k, v, acc), f) + } +} |