Comments (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.
@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.
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.
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.
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)
- HTML function component
- How to speed up `Elixir` compile times
- Bumblebee: GPT2, Stable Diffusion, and more in Elixir!
- Sheldon: The Erlang Spell Checker
- About comprehensions in Elixir
- Create a Livebook sub repo? HOT 10
- livebook on genservers HOT 2
- Simplifying Systems with Elixir • Sasa Juric • YOW! 2020 HOT 1
- livebook (in progres) on Finite State Machines HOT 1
- Block Based Editor in Phoenix LiveView
- React to LiveView for Performance
- Phoenix LiveView 0.19 + `todo_trek`
- Machine Learning with Elixir book HOT 2
- Elixir for cynical curmudgeons HOT 1
- Unpacking Elixir: Concurrency
- Secure Coding and Deployment Hardening Guidelines
- [Video] ElixirConf 2023 - José Valim - foundations of the `Elixir` type system HOT 1
- Env variables: how to? HOT 16
- Building AI Apps with Elixir - Charlie Holtz - ElixirConf 2023 HOT 4
- How to install `Erlang` and `Elixir` on `macOS` with `M1` Chip HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from learn-elixir.