I would use comprehensions:
for item <- 1, 2, 3,
rem(item, 2) == 0,
do: item * 2
There is no reason for Enum.filter_map or Enum.map_filter to exist besides
backwards compatibility.
*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D
On Wed, Apr 26, 2017 at 12:42 PM, Łukasz Niemier <[email protected]> wrote:
> 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/ms
> gid/elixir-lang-core/053143ce-efec-44f3-8e44-45bc36b90a67%
> 40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/053143ce-efec-44f3-8e44-45bc36b90a67%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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/CAGnRm4K331gAD3RRxOCYd38CFhBwVa6VpsOMkpzw6f6_bzrZ3Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.