@@ -1414,14 +1414,14 @@ defmodule Kernel do
1414
1414
iex> inspect [1, 2, 3, 4, 5], limit: 3
1415
1415
"[1, 2, 3, ...]"
1416
1416
1417
- iex> inspect("josé " <> <<0>>)
1418
- "<<106, 111, 115 , 195, 169 , 0>>"
1417
+ iex> inspect("olá " <> <<0>>)
1418
+ "<<111, 108 , 195, 161 , 0>>"
1419
1419
1420
- iex> inspect("josé " <> <<0>>, binaries: :as_strings)
1421
- "\" josé \\000\" "
1420
+ iex> inspect("olá " <> <<0>>, binaries: :as_strings)
1421
+ "\" olá \\000\" "
1422
1422
1423
- iex> inspect("josé ", binaries: :as_binaries)
1424
- "<<106, 111, 115 , 195, 169 >>"
1423
+ iex> inspect("olá ", binaries: :as_binaries)
1424
+ "<<111, 108 , 195, 161 >>"
1425
1425
1426
1426
Note that the inspect protocol does not necessarily return a valid
1427
1427
representation of an Elixir term. In such cases, the inspected result
@@ -1457,18 +1457,18 @@ defmodule Kernel do
1457
1457
## Example
1458
1458
1459
1459
defmodule User do
1460
- defstruct name: "jose "
1460
+ defstruct name: "john "
1461
1461
end
1462
1462
1463
1463
struct(User)
1464
- #=> %User{name: "jose "}
1464
+ #=> %User{name: "john "}
1465
1465
1466
- opts = [name: "eric "]
1466
+ opts = [name: "meg "]
1467
1467
user = struct(User, opts)
1468
- #=> %User{name: "eric "}
1468
+ #=> %User{name: "meg "}
1469
1469
1470
1470
struct(user, unknown: "value")
1471
- #=> %User{name: "eric "}
1471
+ #=> %User{name: "meg "}
1472
1472
1473
1473
"""
1474
1474
@ spec struct ( module | map , Enum . t ) :: map
@@ -1508,22 +1508,22 @@ defmodule Kernel do
1508
1508
1509
1509
## Examples
1510
1510
1511
- iex> users = %{"josé " => %{age: 27}, "eric " => %{age: 23}}
1512
- iex> get_in(users, ["josé ", :age])
1511
+ iex> users = %{"john " => %{age: 27}, "meg " => %{age: 23}}
1512
+ iex> get_in(users, ["john ", :age])
1513
1513
27
1514
1514
1515
1515
In case any of entries in the middle returns `nil`, `nil` will be returned
1516
1516
as per the Access protocol:
1517
1517
1518
- iex> users = %{"josé " => %{age: 27}, "eric " => %{age: 23}}
1518
+ iex> users = %{"john " => %{age: 27}, "meg " => %{age: 23}}
1519
1519
iex> get_in(users, ["unknown", :age])
1520
1520
nil
1521
1521
1522
1522
When one of the keys is a function, the function is invoked.
1523
1523
In the example below, we use a function to get all the maps
1524
1524
inside a list:
1525
1525
1526
- iex> users = [%{name: "josé ", age: 27}, %{name: "eric ", age: 23}]
1526
+ iex> users = [%{name: "john ", age: 27}, %{name: "meg ", age: 23}]
1527
1527
iex> all = fn :get, data, next -> Enum.map(data, next) end
1528
1528
iex> get_in(users, [all, :age])
1529
1529
[27, 23]
@@ -1560,9 +1560,9 @@ defmodule Kernel do
1560
1560
1561
1561
## Examples
1562
1562
1563
- iex> users = %{"josé " => %{age: 27}, "eric " => %{age: 23}}
1564
- iex> put_in(users, ["josé ", :age], 28)
1565
- %{"josé " => %{age: 28}, "eric " => %{age: 23}}
1563
+ iex> users = %{"john " => %{age: 27}, "meg " => %{age: 23}}
1564
+ iex> put_in(users, ["john ", :age], 28)
1565
+ %{"john " => %{age: 28}, "meg " => %{age: 23}}
1566
1566
1567
1567
In case any of entries in the middle returns `nil`,
1568
1568
an error will be raised when trying to access it next.
@@ -1582,9 +1582,9 @@ defmodule Kernel do
1582
1582
1583
1583
## Examples
1584
1584
1585
- iex> users = %{"josé " => %{age: 27}, "eric " => %{age: 23}}
1586
- iex> update_in(users, ["josé ", :age], &(&1 + 1))
1587
- %{"josé " => %{age: 28}, "eric " => %{age: 23}}
1585
+ iex> users = %{"john " => %{age: 27}, "meg " => %{age: 23}}
1586
+ iex> update_in(users, ["john ", :age], &(&1 + 1))
1587
+ %{"john " => %{age: 28}, "meg " => %{age: 23}}
1588
1588
1589
1589
In case any of entries in the middle returns `nil`,
1590
1590
an error will be raised when trying to access it next.
@@ -1619,20 +1619,20 @@ defmodule Kernel do
1619
1619
update it at the same time. For example, it could be used to increase
1620
1620
the age of a user by one and return the previous age in one pass:
1621
1621
1622
- iex> users = %{"josé " => %{age: 27}, "eric " => %{age: 23}}
1623
- iex> get_and_update_in(users, ["josé ", :age], &{&1, &1 + 1})
1624
- {27, %{"josé " => %{age: 28}, "eric " => %{age: 23}}}
1622
+ iex> users = %{"john " => %{age: 27}, "meg " => %{age: 23}}
1623
+ iex> get_and_update_in(users, ["john ", :age], &{&1, &1 + 1})
1624
+ {27, %{"john " => %{age: 28}, "meg " => %{age: 23}}}
1625
1625
1626
1626
When one of the keys is a function, the function is invoked.
1627
1627
In the example below, we use a function to get and increment all
1628
1628
ages inside a list:
1629
1629
1630
- iex> users = [%{name: "josé ", age: 27}, %{name: "eric ", age: 23}]
1630
+ iex> users = [%{name: "john ", age: 27}, %{name: "meg ", age: 23}]
1631
1631
iex> all = fn :get_and_update, data, next ->
1632
1632
...> Enum.map(data, next) |> List.unzip() |> List.to_tuple()
1633
1633
...> end
1634
1634
iex> get_and_update_in(users, [all, :age], &{&1, &1 + 1})
1635
- {[27, 23], [%{name: "josé ", age: 28}, %{name: "eric ", age: 24}]}
1635
+ {[27, 23], [%{name: "john ", age: 28}, %{name: "meg ", age: 24}]}
1636
1636
1637
1637
If the previous value before invoking the function is nil,
1638
1638
the function *will* receive `nil` as a value and must handle it
@@ -1670,13 +1670,13 @@ defmodule Kernel do
1670
1670
1671
1671
## Examples
1672
1672
1673
- iex> users = %{"josé " => %{age: 27}, "eric " => %{age: 23}}
1674
- iex> put_in(users["josé "][:age], 28)
1675
- %{"josé " => %{age: 28}, "eric " => %{age: 23}}
1673
+ iex> users = %{"john " => %{age: 27}, "meg " => %{age: 23}}
1674
+ iex> put_in(users["john "][:age], 28)
1675
+ %{"john " => %{age: 28}, "meg " => %{age: 23}}
1676
1676
1677
- iex> users = %{"josé " => %{age: 27}, "eric " => %{age: 23}}
1678
- iex> put_in(users["josé "].age, 28)
1679
- %{"josé " => %{age: 28}, "eric " => %{age: 23}}
1677
+ iex> users = %{"john " => %{age: 27}, "meg " => %{age: 23}}
1678
+ iex> put_in(users["john "].age, 28)
1679
+ %{"john " => %{age: 28}, "meg " => %{age: 23}}
1680
1680
1681
1681
"""
1682
1682
defmacro put_in ( path , value ) do
@@ -1703,13 +1703,13 @@ defmodule Kernel do
1703
1703
1704
1704
## Examples
1705
1705
1706
- iex> users = %{"josé " => %{age: 27}, "eric " => %{age: 23}}
1707
- iex> update_in(users["josé "][:age], &(&1 + 1))
1708
- %{"josé " => %{age: 28}, "eric " => %{age: 23}}
1706
+ iex> users = %{"john " => %{age: 27}, "meg " => %{age: 23}}
1707
+ iex> update_in(users["john "][:age], &(&1 + 1))
1708
+ %{"john " => %{age: 28}, "meg " => %{age: 23}}
1709
1709
1710
- iex> users = %{"josé " => %{age: 27}, "eric " => %{age: 23}}
1711
- iex> update_in(users["josé "].age, &(&1 + 1))
1712
- %{"josé " => %{age: 28}, "eric " => %{age: 23}}
1710
+ iex> users = %{"john " => %{age: 27}, "meg " => %{age: 23}}
1711
+ iex> update_in(users["john "].age, &(&1 + 1))
1712
+ %{"john " => %{age: 28}, "meg " => %{age: 23}}
1713
1713
1714
1714
"""
1715
1715
defmacro update_in ( path , fun ) do
@@ -1735,9 +1735,9 @@ defmodule Kernel do
1735
1735
1736
1736
## Examples
1737
1737
1738
- iex> users = %{"josé " => %{age: 27}, "eric " => %{age: 23}}
1739
- iex> get_and_update_in(users["josé "].age, &{&1, &1 + 1})
1740
- {27, %{"josé " => %{age: 28}, "eric " => %{age: 23}}}
1738
+ iex> users = %{"john " => %{age: 27}, "meg " => %{age: 23}}
1739
+ iex> get_and_update_in(users["john "].age, &{&1, &1 + 1})
1740
+ {27, %{"john " => %{age: 28}, "meg " => %{age: 23}}}
1741
1741
1742
1742
## Paths
1743
1743
@@ -1752,15 +1752,15 @@ defmodule Kernel do
1752
1752
1753
1753
Here are some valid paths:
1754
1754
1755
- users["josé "][:age]
1756
- users["josé "].age
1757
- User.all["josé "].age
1758
- all_users()["josé "].age
1755
+ users["john "][:age]
1756
+ users["john "].age
1757
+ User.all["john "].age
1758
+ all_users()["john "].age
1759
1759
1760
1760
Here are some invalid ones:
1761
1761
1762
1762
# Does a remote call after the initial value
1763
- users["josé "].do_something(arg1, arg2)
1763
+ users["john "].do_something(arg1, arg2)
1764
1764
1765
1765
# Does not access any field
1766
1766
users
@@ -2912,7 +2912,7 @@ defmodule Kernel do
2912
2912
is used:
2913
2913
2914
2914
defmodule User do
2915
- defstruct name: "José ", age: 25
2915
+ defstruct name: "john ", age: 25
2916
2916
@type t :: %User{name: String.t, age: integer}
2917
2917
end
2918
2918
0 commit comments