@@ -979,12 +979,14 @@ defmodule Map do
979
979
`fun` receives the key and value of each of the
980
980
elements in the map as a key-value pair.
981
981
982
- `Map.filter/2` is faster than using `map |> Enum.filter(fun) |> Enum.into(%{})`,
983
- as no intermediate list is being built.
984
-
985
982
See also `reject/2` which discards all elements where the
986
983
function returns a truthy value.
987
984
985
+ > Note: if you find yourself doing multiple calls to `Map.map/2`
986
+ > and `Map.filter/2` in a pipeline, it is likely more efficient
987
+ > to use `Enum.map/2` and `Enum.filter/2` instead and convert to
988
+ > a map at the end using `Map.new/1`.
989
+
988
990
## Examples
989
991
990
992
iex> Map.filter(%{one: 1, two: 2, three: 3}, fn {_key, val} -> rem(val, 2) == 1 end)
@@ -1010,9 +1012,8 @@ defmodule Map do
1010
1012
end
1011
1013
1012
1014
@ doc """
1013
- Returns map excluding the pairs from `map` for which `fun` returns a truthy value.
1014
- `Map.reject/2` is faster than using `map |> Enum.reject(fun) |> Enum.into(%{})`,
1015
- as no intermediate list is being built.
1015
+ Returns map excluding the pairs from `map` for which `fun` returns
1016
+ a truthy value.
1016
1017
1017
1018
See also `filter/2`.
1018
1019
@@ -1041,8 +1042,15 @@ defmodule Map do
1041
1042
end
1042
1043
1043
1044
@ doc """
1044
- Maps the function `fun` over all key-value pairs in `map`, returning a map
1045
- with all the values replaced with the result of the function.
1045
+ Maps the function `fun` over all key-value pairs in `map`
1046
+
1047
+ It returns a map with all the values replaced with the result
1048
+ of the function.
1049
+
1050
+ > Note: if you find yourself doing multiple calls to `Map.map/2`
1051
+ > and `Map.filter/2` in a pipeline, it is likely more efficient
1052
+ > to use `Enum.map/2` and `Enum.filter/2` instead and convert to
1053
+ > a map at the end using `Map.new/1`.
1046
1054
1047
1055
## Examples
1048
1056
0 commit comments