Skip to content

Commit 7d2cee2

Browse files
axelsonJosé Valim
authored andcommitted
Increase understandability of the tuple documentation (#9226)
[ci skip] Since Elixir data structures are immutable, emphasize that creating a new tuple is required. Also add a "result" binding to make it more clear that the last line is being used as a result for later.
1 parent a58a924 commit 7d2cee2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/elixir/lib/tuple.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@ defmodule Tuple do
3131
3232
The functions in this module that add and remove elements from tuples are
3333
rarely used in practice, as they typically imply tuples are being used as
34-
collections. To append to a tuple, it is preferable to use pattern matching:
34+
collections. To append to a tuple, it is preferable to extract the elements
35+
from the old tuple with pattern matching, and then create a new tuple:
3536
3637
tuple = {:ok, :example}
3738
3839
# Avoid
39-
Tuple.insert_at(tuple, 2, %{})
40+
result = Tuple.insert_at(tuple, 2, %{})
4041
4142
# Prefer
4243
{:ok, atom} = tuple
43-
{:ok, atom, %{}}
44+
result = {:ok, atom, %{}}
4445
4546
"""
4647

0 commit comments

Comments
 (0)