-
Notifications
You must be signed in to change notification settings - Fork 109
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
Comments
I don't think that my original understanding is correct because:
|
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 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 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. |
Thanks @YvesMuyaBenda, seems like a potentially confusing area. I will try to clean up this area in the README so it is clearer. |
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 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! |
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 ofa
would be0
,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.
The text was updated successfully, but these errors were encountered: