DockYard-Academy / curriculum

MIT License
947 stars 245 forks source link

Tuples: Collections or not collections? #392

Closed BigSpaces closed 1 year ago

BigSpaces commented 1 year ago

Hello Brook,

In the non-enumerables module, you mention that tuples are not collections.

I was checking here: https://elixirschool.com/en/lessons/basics/collections

...and it says they are.

What's the "source of truth"?

Thanks

BigSpaces commented 1 year ago

I didn't mean to use the issues as a place to raise a doubt. I meant it as a way to double-check the content of that page to avoid confusion in students. Sorry for not being clear above.

BrooklinJazz commented 1 year ago

This is a great use of issues. Thank you for bringing this up, I think I can improve the material to make this more clear.

Tuples are not enumerable (meaning they don't work with the Enum module),

The functions in this module that add and remove elements from tuples are rarely used in practice, as they typically imply tuples are being used as collections. To append to a tuple, it is preferable to extract the elements from the old tuple with pattern matching, and then create a new tuple: https://hexdocs.pm/elixir/1.12/Tuple.html

Another interesting conversation around the topic.

https://stackoverflow.com/questions/41334109/why-tuples-are-not-enumerable-in-elixir

I think that we should clarify the lesson to say they are not enumerable, rather than saying they are not collections.

They are not intended to be used as collections, however, I'm honestly not sure if they are "technically not collections" and can't find anything to confirm this. So to make this more accurate, we should change the wording to say they are "not enumberable" rather than "not collections".

BigSpaces commented 1 year ago

Thank you, Brook.

I appreciate you taking the time to unpack this one for me in the midst of a very busy schedule and workload.

When I went to the stackoverflow discussion to dive deeper into ti, I had this type of experience: https://youtu.be/LKCi0gDF_d8?t=15

It is like I am reading ancient Greek still :D To be expected at this point, I guess.

Looking forward to continuing the process today.

Jon

On Mon, Sep 26, 2022, at 9:43 AM, Brooklin Myers wrote:

This is a great use of issues. Thank you for bringing this up, I think I can improve the material to make this more clear.

Tuples are not enumerable (meaning they don't work with the Enum module),

The functions in this module that add and remove elements from tuples are rarely used in practice, as they typically imply tuples are being used as collections. To append to a tuple, it is preferable to extract the elements from the old tuple with pattern matching, and then create a new tuple: https://hexdocs.pm/elixir/1.12/Tuple.html

Another interesting conversation around the topic.

https://stackoverflow.com/questions/41334109/why-tuples-are-not-enumerable-in-elixir

I think that we should clarify the lesson to say they are not enumerable, rather than saying they are not collections.

They are not intended to be used as collections, however, I'm honestly not sure if they are "technically not collections" and can't find anything to confirm this. So to make this more accurate, we should change the wording to say they are "not enumberable" rather than "not collections".

— Reply to this email directly, view it on GitHub https://github.com/DockYard-Academy/beta_curriculum/issues/392#issuecomment-1257627926, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3CCQZ6CGZ7OBTWEZU5QUA3WAFH3RANCNFSM6AAAAAAQVKQ4N4. You are receiving this because you authored the thread.Message ID: @.***>