Skip to content

Commit

Permalink
Merge pull request #9252 from iri/iri/lib/updated_maps_docs
Browse files Browse the repository at this point in the history
Updated doc for maps:foreach/2. Added example for maps:foreach/2.
  • Loading branch information
garazdawi authored Jan 8, 2025
2 parents 6dfe729 + a1648fd commit 07e897b
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/stdlib/src/maps.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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<erl_eval.41.18682967>
> 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
Expand All @@ -815,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.
Expand Down Expand Up @@ -859,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`.
Expand Down

0 comments on commit 07e897b

Please sign in to comment.