Giter VIP home page Giter VIP logo

Comments (5)

Cleop avatar Cleop commented on May 20, 2024 5

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.

from learn-elixir.

YvesMuyaBenda avatar YvesMuyaBenda commented on May 20, 2024 5

@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!

from learn-elixir.

YvesMuyaBenda avatar YvesMuyaBenda commented on May 20, 2024 2

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.

from learn-elixir.

Cleop avatar Cleop commented on May 20, 2024 2

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

from learn-elixir.

Cleop avatar Cleop commented on May 20, 2024

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.

from learn-elixir.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.