Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What does 'enumerable' mean? #39

Closed
Cleop opened this issue Mar 27, 2017 · 5 comments
Closed

What does 'enumerable' mean? #39

Cleop opened this issue Mar 27, 2017 · 5 comments
Assignees
Labels
awaiting-review An issue or pull request that needs to be reviewed question A question needs to be answered before progress can be made on this issue

Comments

@Cleop
Copy link
Member

Cleop commented Mar 27, 2017

Lists are enumerable, What does enumerable mean?

Is the meaning of enumerable that you can refer to a value by numerical reference (by counting from left to right)?

Say I have a list: ["a", "b", "c"], the numerical reference/ index of a would be 0, b = 1, c = 2?

I've looked at dictionary definitions as well as this forum question: http://softwareengineering.stackexchange.com/questions/199592/what-does-enumerable-mean and can't tell if it's more complex than my original assumption.

@Cleop Cleop added question A question needs to be answered before progress can be made on this issue help wanted If you can help make progress with this issue, please comment! labels Mar 27, 2017
@Cleop
Copy link
Member Author

Cleop commented Mar 27, 2017

I don't think that my original understanding is correct because:

Tuples are not enumerable yet the README then goes on to illustrate an example of calling a tuple value by index which goes against my initial understanding for what could demonstrate an enumerable value.

@YvesMuyaBenda
Copy link

YvesMuyaBenda commented Mar 27, 2017

Hello @Cleop, while you are waiting for other replies, and not pretending to know much about Elixir, but using some googlfu and general knowledge, I think the following discussion might prove helpful Tuples aren't Enumerable? Now, the key passage in the discussion for me is: "Tuples don't support the Enumerable protocol? They sure seem enumerable when you can ask elem {:a, :b, :c}, 1 and get :b."

So there seems to be two concepts that are perhaps being conflated within the concept of "enumerable", one of which is being able to be indexed, and the other is supporting the Enumerable protocol in Elixir. As you have seen, tuples do appear to be able to be indexed, so by elimination what is probably meant is that tuples do not support the Enumerable Protocol.

So, I think that "tuples are not enumerable" imply that tuples is not a type that supports the Enumerable protocol, which implies you cannot call certain functions on tuples, that you can call on those collection types that do support the protocol, such as lists.

Also useful in the discussion linked above is the following passage:

"Tuples also aren't meant to be iterated over, don't get confused by the
fact that you could using elem/2 and size/1. Tuples are for storing
multiple pieces of information together, which does not imply that they
are intended for storing a collection."

Anyways, that is my best guess, based on a little research. Hopefully, something is useful here for you, and if I have made some errors, others will come along to throw some light.

@Cleop
Copy link
Member Author

Cleop commented Mar 28, 2017

Thanks @YvesMuyaBenda, seems like a potentially confusing area. I will try to clean up this area in the README so it is clearer.

@Cleop Cleop added the in-progress An issue or pull request that is being worked on by the assigned person label Mar 28, 2017
@Cleop
Copy link
Member Author

Cleop commented Mar 28, 2017

So to clarify:

Enumerable values at the most basic level are values that can be 'counted by one-to-one correspondence with the set of all positive integers'. In other words, values that can be referenced and obtained by index.

In Elixir both list and tuple values can be referenced by index.

A second feature of enumerable values is that the values can be iterated over ie. using functions like map or each. In Elixir these kinds of functions are found in the Enumerable Protocol, Enum and Stream modules. Lists can use both of these modules as outlined in the Enumerable Protocol. Whilst tuples may be considered 'enumerable' as you can refer to them by index, you may also not consider them enumerable because they are not included in the Enumerable Protocol and do not work with the Enum and Stream modules.

@Cleop Cleop self-assigned this Mar 28, 2017
@YvesMuyaBenda
Copy link

YvesMuyaBenda commented Mar 28, 2017

@Cleop Your writing is so smooth and concise for tech writing, with an excellent use of bold emphasis! What you wrote is my current understanding of the parts of the concept "enumerable" and how they relate. The key thing is that the discussion takes place within the specific context of Elixir, which you highlighted in your second paragraph, with the prepositional phrase "In Elixir". Good stuff!

@Cleop Cleop removed the help wanted If you can help make progress with this issue, please comment! label Mar 28, 2017
Cleop added a commit that referenced this issue Mar 30, 2017
@Cleop Cleop added awaiting-review An issue or pull request that needs to be reviewed and removed in-progress An issue or pull request that is being worked on by the assigned person labels Mar 30, 2017
@iteles iteles closed this as completed in 0f07017 Apr 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review An issue or pull request that needs to be reviewed question A question needs to be answered before progress can be made on this issue
Projects
None yet
Development

No branches or pull requests

2 participants