[Proposal] {Enum, Stream}.zip_all

46 views
Skip to first unread message

Greg Rychlewski

unread,
Jun 13, 2021, 1:27:53 PM6/13/21
to elixir-lang-core
Hi,

Would the community be interested in adding versions of of the Enum/Stream zip functions that allow for a default value to be set when the enumerables aren't all the same length?  I was thinking of the following name/arity combos:

{Enum, Stream}.zip_all/2 
{Enum, Stream}.zip_all/3 
{Enum, Stream}.zip_all_with/3
{Enum, Stream}.zip_all_with/4
Enum.zip_all_reduce/4
Enum.zip_all_reduce/5

I had some ideas for how to implement this and could work on a PR if the proposal is accepted.

Thanks

Christopher Keele

unread,
Jun 14, 2021, 1:13:35 PM6/14/21
to elixir-lang-core
Not commenting on the feature itself, but I believe there's a convention in the collection stdlib of keeping the same function names, but accept an extra parameter, for default values. See:
  • Enum.find/3
  • Enum.find_value/3
  • Map.pop/3
  • Keyword.get/3

Greg Rychlewski

unread,
Jun 14, 2021, 2:14:24 PM6/14/21
to elixir-lang-core
Thanks. I was thinking about that too, but for this particular feature I believe there would be an issue. Please let me know what you think: 

If we take Enum.zip as an example, it has a 1-arity version for accepting a list of enumerables and a 2-arity version accepting two single enumerables as arguments. If we wanted to allow for a default value in the zip/1 version it would conflict with the existing zip/2. 

Reply all
Reply to author
Forward
0 new messages