Enum.transpose/1 or List.transpose/1

54 views
Skip to first unread message

Oskar

unread,
Dec 3, 2021, 7:56:15 AM12/3/21
to elixir-lang-core
Hi!

Would you be open to `Enum.transpose(enumerable)` or `List.transpose(list)` functions? You can already transpose a list with `Enum.zip_with(list, & &1)` and `Stream.zip_with(list, & &1)`, however it's a bit difficult to understand the intent on first glance, whereas `transpose/1` would be a clear operation. I am unsure how other enumerables would fit into this, so maybe it should go under the List module.

What do you think?

Oskar

Oskar

unread,
Dec 3, 2021, 8:00:34 AM12/3/21
to elixir-lang-core
To clarify, the list variable in my example is a two-dimensional list, e.g. [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

José Valim

unread,
Dec 3, 2021, 8:03:20 AM12/3/21
to elixir-l...@googlegroups.com
Hi Oskar,

I think the best option in this case is to move it to a private function called transpose and then call Enum.zip_with/2. This makes the intent clear without adding to the API, especially because the term transpose it self can be overloaded.

--
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/9c2526e3-02af-4189-8bbf-6365a72ce72fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages