From 839de22be938cf87b34e83ebdbd15f864c6ae5a3 Mon Sep 17 00:00:00 2001 From: Cohen Carlisle Date: Wed, 13 May 2026 16:29:03 -0400 Subject: [PATCH] mirror Map.filter/2 perf note in Map.reject/2 also slightly tweak wording of performance note: use and/or for clarity (pipeline could contain only filters or rejects) recommend using Enum.filter and reject instead of Enum.map and filter point to Map.new/2 in addition to Map.new/1 --- lib/elixir/lib/map.ex | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/elixir/lib/map.ex b/lib/elixir/lib/map.ex index 9897d75574..ee56679d64 100644 --- a/lib/elixir/lib/map.ex +++ b/lib/elixir/lib/map.ex @@ -1138,9 +1138,9 @@ defmodule Map do > #### Performance considerations {: .tip} > > If you find yourself doing multiple calls to `Map.filter/2` - > and `Map.reject/2` in a pipeline, it is likely more efficient - > to use `Enum.map/2` and `Enum.filter/2` instead and convert to - > a map at the end using `Map.new/1`. + > and/or `Map.reject/2` in a pipeline, it is likely more efficient + > to use `Enum.filter/2` and `Enum.reject/2` instead and convert to + > a map at the end using `Map.new/1` or `Map.new/2`. ## Examples @@ -1172,6 +1172,13 @@ defmodule Map do See also `filter/2`. + > #### Performance considerations {: .tip} + > + > If you find yourself doing multiple calls to `Map.filter/2` + > and/or `Map.reject/2` in a pipeline, it is likely more efficient + > to use `Enum.filter/2` and `Enum.reject/2` instead and convert to + > a map at the end using `Map.new/1` or `Map.new/2`. + ## Examples iex> Map.reject(%{one: 1, two: 2, three: 3}, fn {_key, val} -> rem(val, 2) == 1 end)