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

Explain why functions returns extra information with tuples #12824

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/elixir/pages/getting-started/lists-and-tuples.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ iex> File.read("path/to/unknown/file")

If the path given to `File.read/1` exists, it returns a tuple with the atom `:ok` as the first element and the file contents as the second. Otherwise, it returns a tuple with `:error` and the error description.

`File.read/1` returns a tuple, not a list, because there it contains always two values and there is no need to update the returned result. Returning a list instead would not bring any advantages.
josevalim marked this conversation as resolved.
Show resolved Hide resolved

Most of the time, Elixir is going to guide you to do the right thing. For example, there is an `elem/2` function to access a tuple item but there is no built-in equivalent for lists:

```elixir
Expand Down