From 1a2083e488658b8c7193b6d796ffca719e683be8 Mon Sep 17 00:00:00 2001 From: iri Date: Tue, 31 Dec 2024 15:25:34 +0300 Subject: [PATCH 1/2] Updated doc for maps:foreach/2. Added example for maps:foreach/2. --- lib/stdlib/src/maps.erl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/stdlib/src/maps.erl b/lib/stdlib/src/maps.erl index f48a5673af6b..c9ac59dec371 100644 --- a/lib/stdlib/src/maps.erl +++ b/lib/stdlib/src/maps.erl @@ -785,11 +785,25 @@ filtermap_1(_Fun, none, _ErrorTag) -> []. -doc """ -Calls `fun F(Key, Value)` for every `Key` to value `Value` association in +Calls `fun Fun(Key, Value)` for every `Key` to value `Value` association in `MapOrIter` in any order. The call fails with a `{badmap,Map}` exception if `MapOrIter` is not a map or valid iterator, or with `badarg` if `Fun` is not a function of arity 2. + +_Example:_ + +```erlang +> Fun = fun(K,V) -> io:format("~p:~p~n",[K,V]) end. +#Fun +> Map = #{"x" => 10, "y" => 20, "z" => 30}. +#{"x" => 10,"y" => 20,"z" => 30} +> maps:foreach(Fun,Map). +"x":10 +"y":20 +"z":30 +ok +``` """. -doc(#{since => <<"OTP 24.0">>}). -spec foreach(Fun,MapOrIter) -> ok when From a1648fd300615c9f3f51d5fcf5d24d2a32816d9b Mon Sep 17 00:00:00 2001 From: iri Date: Thu, 2 Jan 2025 00:37:43 +0300 Subject: [PATCH 2/2] Removed inconsistency between text and -spec --- lib/stdlib/src/maps.erl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/stdlib/src/maps.erl b/lib/stdlib/src/maps.erl index c9ac59dec371..e577f6030853 100644 --- a/lib/stdlib/src/maps.erl +++ b/lib/stdlib/src/maps.erl @@ -829,8 +829,8 @@ foreach_1(_Fun, none, _ErrorTag) -> ok. -doc """ -Calls `F(Key, Value, AccIn)` for every `Key` to value `Value` association in -`MapOrIter` in any order. Function `fun F/3` must return a new accumulator, +Calls `Fun(Key, Value, AccIn)` for every `Key` to value `Value` association in +`MapOrIter` in any order. Function `fun Fun/3` must return a new accumulator, which is passed to the next successive call. This function returns the final value of the accumulator. The initial accumulator value `Init` is returned if the map is empty. @@ -873,7 +873,7 @@ fold_1(_Fun, Acc, none, _ErrorTag) -> Acc. -doc """ -Produces a new map `Map` by calling function `fun F(Key, Value1)` for every +Produces a new map `Map` by calling function `fun Fun(Key, Value1)` for every `Key` to value `Value1` association in `MapOrIter` in any order. Function `fun Fun/2` must return value `Value2` to be associated with key `Key` for the new map `Map`.