You are right! I completely missed that there was a ternary version of 
`Enum.into`.

Let me refine the proposal:

- Update the documentation of `Enum.map` to reference `Enum.into/3`.
- Increase performance of `Enum.into/3` when the collectable is a map, by 
collecting to a list and in the end call `:maps.from_list` on the result. 
(As Ben Wilson explained, this is a lot faster/cleaner than *n* `Map.put` 
calls)


~Wiebe-Marten

On Thursday, July 7, 2016 at 7:24:16 PM UTC+2, Andrea Leopardi wrote:
>
> Enum.into/3 should do what you want :)
>
> On Thursday, 7 July 2016, Wiebe-Marten Wijnja <[email protected] 
> <javascript:>> wrote:
>
>> I propose to add `into: collectable` as optional third argument to 
>> Enum.map. 
>>
>> This would allow mapping over things without first converting it to a 
>> list and then convert it back.
>>
>> So:
>>
>> %{"a" => 1, "b" => 2}
>> |> Enum.map(fn {k, v} -> {String.upcase(k), v} end)
>> |> Enum.into(%{})
>>
>> could be written as:
>>
>> %{"a" => 1, "b" => 2}
>> |> Enum.map(fn {k, v} -> {String.upcase(k), v} end, into: %{})
>>
>> Not having to do the list conversion in the middle might also improve 
>> performance.
>>
>>
>> Right now, enumerating and collecting in one go is of course possible 
>> using `Kernel.SpecialForms.for`. `for` is however not very 
>> pipeline-friendly.
>>
>>
>> What do you think?
>>
>>
>> Sincerely,
>>
>> ~Wiebe-Marten
>>
>> -- 
>> 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/23c345b9-9ba1-48ea-8db0-6d2e9e700473%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/elixir-lang-core/23c345b9-9ba1-48ea-8db0-6d2e9e700473%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> -- 
>
> Andrea Leopardi
> [email protected] <javascript:>
>
>

-- 
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/5634346f-35a1-4b77-a910-78317e31db10%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to