as a not related side note, often I do not use `reduce` for that kind of
pattern because I feeli
def treat(list), do: _treat(list, [])
defp _treat(list, result)
defp _treat([], result), do: result
defp _treat([head|tail], result) do
...
treat(tail, ...)
end
is often more readable, but there is no account for taste.
--
Non datemi consigli che so sbagliare da solo
(Giuseppe Di Stefano)
On Sun, Mar 31, 2019 at 7:06 PM 'Justin Wood' via elixir-lang-core <
[email protected]> wrote:
> Is there a reason you are not using List.foldl/3?
>
> List.foldl list, [], (fn elem, acc -> [f(x) | acc] end)
>
> Can I ask why you are reversing a list, traversing it, just to reverse it
> again?
>
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Sunday, 31 March 2019 11:58, Robert Dober <[email protected]>
> wrote:
>
> Hi there
>
> I do this all the time, travering a reversed list and accumulating a
> transformation into a new list, unreversed now.
>
> Is this not a very frequent FP pattern.
>
> I would quite happy to use `Enum.reverse_map` which would be more efficent
> than my eternal internal remimplementation:
>
> ```elixir
>
> defp map_reverse(collection, fun)
> do
>
> _map_reverse(collection, fun,
> [])
>
>
> end
>
>
>
> defp _map_reverse(collection, fun,
> result)
>
> defp _map_reverse([], _, result)
> do
>
>
> result
>
>
> end
>
> defp _map_reverse([head|rest], fun, result)
> do
>
> _map_reverse(rest, fun,
> [fun.(head)|result])
>
> end
> ```
>
> Any thoughts?
>
> KR
> Robert
>
>
> --
> 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/a4fe903e-9661-448e-ba80-0b8cfc4f8bff%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/a4fe903e-9661-448e-ba80-0b8cfc4f8bff%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/2EnP_1aGY4v5K8ZXMJqL8zuTgVP44FLKVnOIEDi1lMmjFaCEot_5CulHgsylJkTkgAWrYEPWNGWciN8nfc3ZeldoLcsm8lWSPecYdGx4Z1s%3D%40protonmail.com
> <https://groups.google.com/d/msgid/elixir-lang-core/2EnP_1aGY4v5K8ZXMJqL8zuTgVP44FLKVnOIEDi1lMmjFaCEot_5CulHgsylJkTkgAWrYEPWNGWciN8nfc3ZeldoLcsm8lWSPecYdGx4Z1s%3D%40protonmail.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/CA%2Bvts6v59Ur5tr_hfLm3vLH8Y_WjBdn-UajX%3DNYwc9jCoxX6kw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.