Add Enum.split_evenly/1

53 views
Skip to first unread message

Masynchin

unread,
Dec 15, 2021, 5:37:38 PM12/15/21
to elixir-lang-core
I think I done it wrong order, so there is link to PR with explanation of when this function is helpful - https://github.com/elixir-lang/elixir/pull/11491

José Valim

unread,
Dec 15, 2021, 5:45:52 PM12/15/21
to elixir-lang-core
Hi Masynchin,

Thank you for the PR!

I think this case can be conveniently done with two traversals, using take_every/drop_every, as you showed, so that's what I propose people do. If the code is very performance oriented, then custom recursion or a reduce loop with two lists as accumulators is the way to go.




On Wed, Dec 15, 2021 at 11:37 PM Masynchin <banzur....@gmail.com> wrote:
I think I done it wrong order, so there is link to PR with explanation of when this function is helpful - https://github.com/elixir-lang/elixir/pull/11491

--
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/bd4d3e3a-7952-4eb3-80e3-c969a4035d6dn%40googlegroups.com.

Masynchin

unread,
Dec 15, 2021, 6:03:27 PM12/15/21
to elixir-lang-core
My english is not so good so I hope I understand it right (please correct me if I am wrong). If it is about using take/drop_every explicitly - I think name like split_evenly can be more describing in long pipes like 123 |> Integer.digits() |> Enum.split_evenly |> Tuple.to_list() |> Enum.map(&Enum.sum/1) than 3-line function, to me it is faster to understand what is going on. But as I mentioned in PR I am new to Elixir and dont know much about Elixir style (paradigm, patterns, common way to write code) so I can be wrong about doing it an another function.
четверг, 16 декабря 2021 г. в 01:45:52 UTC+3, José Valim:

José Valim

unread,
Dec 15, 2021, 6:19:35 PM12/15/21
to elixir-lang-core
split_evenly is definitely clearer but I don't think it is common enough to warrant inclusion into the standard library, especially when you can achieve  it with two operations using take_every/drop_every.

And your English is perfectly fine! :)

Reply all
Reply to author
Forward
0 new messages