Map.filter(map, predicate)
in Elixir as well instead of doingmap |> Enum.filter(predicate) |> Enum.into(%{})
for {key, value} <- map, some_filter(key, value), into: %{}, do: {key, value}
The first one alternative is slower, b/c of 2-step transformation, and the second one consume more memory, could not be piped and has a lack of expressiveness (too imperative way to do a simple filtration).
--
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 elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/5d403c4a-91f8-4c4d-8dc0-297185a2aed8%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAAPY6eO5aDifRxHxv7QtD4%3Di_bYbUw1sphxMhq4jEjuR9naPSQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAKL9qdTxQWdKDM7B%3D1XLkf7w9PeshpfSyrpsuhM%3DeaEqdZVSDA%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-l...@googlegroups.com.
We should also address the fact that if we add Map.filter/2, we also likely have to add Map.drop/2 (to mimic Enum and Stream), but that name is already taken.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/5d403c4a-91f8-4c4d-8dc0-297185a2aed8%40googlegroups.com.
--
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 elixir-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAAPY6eO5aDifRxHxv7QtD4%3Di_bYbUw1sphxMhq4jEjuR9naPSQ%40mail.gmail.com.
--
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 elixir-l...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAKL9qdTxQWdKDM7B%3D1XLkf7w9PeshpfSyrpsuhM%3DeaEqdZVSDA%40mail.gmail.com.
--Andrea Leopardi
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/c819a8cc-c3b6-41cc-a056-76a294b79fb6%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/c819a8cc-c3b6-41cc-a056-76a294b79fb6%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/13ab9f68-3895-47b1-bd7f-dee62f1a2e66%40googlegroups.com.
--
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 elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/fd2477c3-0983-4cba-a1fb-7de308fee6dfn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/E41D08E3-85FF-422B-A48A-6AC129CF3C72%40resilia.nl.
It can clearly be seen from this graph that the difference in
implementations is very small.
Especially the difference between direct_filter_inlined/2
vs. :maps.filter/2
is neglegible.
wrapped_filter/2
is,
as was expected, a little bit (averaging at ~20-40%) slower than
the former two.
On average, the direct_filter_inlined/2
seems to
be slightly faster than the non-inlined version.
This difference is small, but significant (i.e. reproducible
across benchmark re-runs).
The particular benchmark I wrote filters all odd values from a
map that has the shape %{0 => 0, 1
=> 1, 2 => 2, ... n => n}.
This seems like an appropriate test for filtering maps, but maybe
there are even better ideas?
~Marten/Qqwy
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4J0DiHv2Pmq%3DY3kvhss_RjrLZRGs3j1yRMS%3DJK7Binrzw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/e35fd630-9955-a674-c02b-d29a17b29f91%40resilia.nl.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAK-y3Cs2%2BQr_m6e_3R41H44iwcj65D4OHT9hZ2_P2FnVPhzE0Q%40mail.gmail.com.
@Allen Madsen:
I have added `Enum.filter` to the benchmark.
Also, by telling the compiler to inline the calls to `next` and
`iterator`, removing redundant guard-clause checks and not
supporting map-iterators (as the rest of the `Map`-module doesn't
expose them either),
`Map.filter` is able to be slightly faster than
`:maps.filter` 🥳.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4L1RaXVAcwCnDvNT9Ze%2BZoghgW7GuAOwbuR6-emeOxPBA%40mail.gmail.com.