In current form `Enum.filter_map/3` isn't always suitable as sometimes we
want to first filter then map and sometimes other way around. This is where
my proposal comes in that will allow both of these behaviours be available
at almost no cost in the same method:
Enum.filter_map([1,2,3], fn item ->
if item % 2 == 0 do
{:keep, item * 2}
else
:ignore
end
end)
This form is IMHO more readable, as it explicitly states the order of
filter and map. This design is based on Rust's
std::tier::Iterator::filter_map
<https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.filter_map>,
however as Elixir doesn't have sum types I needed to use some form of
tuple/atom workaround.
--
You received this message because you are subscribed to the Google Groups
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/053143ce-efec-44f3-8e44-45bc36b90a67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.