Skip to content

Commit 50af805

Browse files
author
José Valim
committed
Use john and meg in code samples
1 parent b1d9e14 commit 50af805

File tree

12 files changed

+173
-173
lines changed

12 files changed

+173
-173
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,14 +1414,14 @@ defmodule Kernel do
14141414
iex> inspect [1, 2, 3, 4, 5], limit: 3
14151415
"[1, 2, 3, ...]"
14161416
1417-
iex> inspect("josé" <> <<0>>)
1418-
"<<106, 111, 115, 195, 169, 0>>"
1417+
iex> inspect("olá" <> <<0>>)
1418+
"<<111, 108, 195, 161, 0>>"
14191419
1420-
iex> inspect("josé" <> <<0>>, binaries: :as_strings)
1421-
"\"josé\\000\""
1420+
iex> inspect("olá" <> <<0>>, binaries: :as_strings)
1421+
"\"olá\\000\""
14221422
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>>"
14251425
14261426
Note that the inspect protocol does not necessarily return a valid
14271427
representation of an Elixir term. In such cases, the inspected result
@@ -1457,18 +1457,18 @@ defmodule Kernel do
14571457
## Example
14581458
14591459
defmodule User do
1460-
defstruct name: "jose"
1460+
defstruct name: "john"
14611461
end
14621462
14631463
struct(User)
1464-
#=> %User{name: "jose"}
1464+
#=> %User{name: "john"}
14651465
1466-
opts = [name: "eric"]
1466+
opts = [name: "meg"]
14671467
user = struct(User, opts)
1468-
#=> %User{name: "eric"}
1468+
#=> %User{name: "meg"}
14691469
14701470
struct(user, unknown: "value")
1471-
#=> %User{name: "eric"}
1471+
#=> %User{name: "meg"}
14721472
14731473
"""
14741474
@spec struct(module | map, Enum.t) :: map
@@ -1508,22 +1508,22 @@ defmodule Kernel do
15081508
15091509
## Examples
15101510
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])
15131513
27
15141514
15151515
In case any of entries in the middle returns `nil`, `nil` will be returned
15161516
as per the Access protocol:
15171517
1518-
iex> users = %{"josé" => %{age: 27}, "eric" => %{age: 23}}
1518+
iex> users = %{"john" => %{age: 27}, "meg" => %{age: 23}}
15191519
iex> get_in(users, ["unknown", :age])
15201520
nil
15211521
15221522
When one of the keys is a function, the function is invoked.
15231523
In the example below, we use a function to get all the maps
15241524
inside a list:
15251525
1526-
iex> users = [%{name: "josé", age: 27}, %{name: "eric", age: 23}]
1526+
iex> users = [%{name: "john", age: 27}, %{name: "meg", age: 23}]
15271527
iex> all = fn :get, data, next -> Enum.map(data, next) end
15281528
iex> get_in(users, [all, :age])
15291529
[27, 23]
@@ -1560,9 +1560,9 @@ defmodule Kernel do
15601560
15611561
## Examples
15621562
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}}
15661566
15671567
In case any of entries in the middle returns `nil`,
15681568
an error will be raised when trying to access it next.
@@ -1582,9 +1582,9 @@ defmodule Kernel do
15821582
15831583
## Examples
15841584
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}}
15881588
15891589
In case any of entries in the middle returns `nil`,
15901590
an error will be raised when trying to access it next.
@@ -1619,20 +1619,20 @@ defmodule Kernel do
16191619
update it at the same time. For example, it could be used to increase
16201620
the age of a user by one and return the previous age in one pass:
16211621
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}}}
16251625
16261626
When one of the keys is a function, the function is invoked.
16271627
In the example below, we use a function to get and increment all
16281628
ages inside a list:
16291629
1630-
iex> users = [%{name: "josé", age: 27}, %{name: "eric", age: 23}]
1630+
iex> users = [%{name: "john", age: 27}, %{name: "meg", age: 23}]
16311631
iex> all = fn :get_and_update, data, next ->
16321632
...> Enum.map(data, next) |> List.unzip() |> List.to_tuple()
16331633
...> end
16341634
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}]}
16361636
16371637
If the previous value before invoking the function is nil,
16381638
the function *will* receive `nil` as a value and must handle it
@@ -1670,13 +1670,13 @@ defmodule Kernel do
16701670
16711671
## Examples
16721672
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}}
16761676
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}}
16801680
16811681
"""
16821682
defmacro put_in(path, value) do
@@ -1703,13 +1703,13 @@ defmodule Kernel do
17031703
17041704
## Examples
17051705
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}}
17091709
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}}
17131713
17141714
"""
17151715
defmacro update_in(path, fun) do
@@ -1735,9 +1735,9 @@ defmodule Kernel do
17351735
17361736
## Examples
17371737
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}}}
17411741
17421742
## Paths
17431743
@@ -1752,15 +1752,15 @@ defmodule Kernel do
17521752
17531753
Here are some valid paths:
17541754
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
17591759
17601760
Here are some invalid ones:
17611761
17621762
# Does a remote call after the initial value
1763-
users["josé"].do_something(arg1, arg2)
1763+
users["john"].do_something(arg1, arg2)
17641764
17651765
# Does not access any field
17661766
users
@@ -2912,7 +2912,7 @@ defmodule Kernel do
29122912
is used:
29132913
29142914
defmodule User do
2915-
defstruct name: "José", age: 25
2915+
defstruct name: "john", age: 25
29162916
@type t :: %User{name: String.t, age: integer}
29172917
end
29182918

lib/elixir/lib/kernel/special_forms.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ defmodule Kernel.SpecialForms do
114114
115115
defmodule User do
116116
def __struct__ do
117-
%{name: "josé", age: 27}
117+
%{name: "john", age: 27}
118118
end
119119
end
120120
121121
In practice though, structs are usually defined with the
122122
`Kernel.defstruct/1` macro:
123123
124124
defmodule User do
125-
defstruct name: "josé", age: 27
125+
defstruct name: "john", age: 27
126126
end
127127
128128
Now a struct can be created as follows:
@@ -132,13 +132,13 @@ defmodule Kernel.SpecialForms do
132132
Underneath a struct is just a map with a `__struct__` field
133133
pointing to the `User` module:
134134
135-
%User{} == %{__struct__: User, name: "josé", age: 27}
135+
%User{} == %{__struct__: User, name: "john", age: 27}
136136
137137
A struct also validates that the given keys are part of the defined
138138
struct. The example below will fail because there is no key
139139
`:full_name` in the `User` struct:
140140
141-
%User{full_name: "José Valim"}
141+
%User{full_name: "john doe"}
142142
143143
Note that a struct specifies a minimum set of keys required
144144
for operations. Other keys can be added to structs via the
@@ -1174,10 +1174,10 @@ defmodule Kernel.SpecialForms do
11741174
Note generators can also be used to filter as it removes any value
11751175
that doesn't match the left side of `<-`:
11761176
1177-
iex> for {:user, name} <- [user: "jose", admin: "john", user: "eric"] do
1177+
iex> for {:user, name} <- [user: "john", admin: "john", user: "meg"] do
11781178
...> String.upcase(name)
11791179
...> end
1180-
["JOSE", "ERIC"]
1180+
["JOHN", "MEG"]
11811181
11821182
Bitstring generators are also supported and are very useful when you
11831183
need to organize bitstring streams:

lib/elixir/lib/record.ex

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule Record do
44
55
Records are simply tuples where the first element is an atom:
66
7-
iex> Record.record? {User, "jose", 27}
7+
iex> Record.record? {User, "john", 27}
88
true
99
1010
This module provides conveniences for working with records at
@@ -29,7 +29,7 @@ defmodule Record do
2929
3030
defmodule MyModule do
3131
require Record
32-
Record.defrecord :user name: "José", age: 25
32+
Record.defrecord :user name: "john", age: 25
3333
3434
@type user :: record(:user, name: String.t, age: integer)
3535
# expands to: `@type user :: {:user, String.t, integer}`
@@ -63,7 +63,7 @@ defmodule Record do
6363
6464
## Examples
6565
66-
iex> record = {User, "jose", 27}
66+
iex> record = {User, "john", 27}
6767
iex> Record.record?(record, User)
6868
true
6969
@@ -91,7 +91,7 @@ defmodule Record do
9191
9292
## Examples
9393
94-
iex> record = {User, "jose", 27}
94+
iex> record = {User, "john", 27}
9595
iex> Record.record?(record)
9696
true
9797
iex> tuple = {}
@@ -126,24 +126,24 @@ defmodule Record do
126126
127127
defmodule User do
128128
require Record
129-
Record.defrecord :user, [name: "José", age: "25"]
129+
Record.defrecord :user, [name: "meg", age: "25"]
130130
end
131131
132132
In the example above, a set of macros named `user` but with different
133133
arities will be defined to manipulate the underlying record:
134134
135135
# To create records
136-
record = user() #=> {:user, "José", 25}
137-
record = user(age: 26) #=> {:user, "José", 26}
136+
record = user() #=> {:user, "meg", 25}
137+
record = user(age: 26) #=> {:user, "meg", 26}
138138
139139
# To get a field from the record
140-
user(record, :name) #=> "José"
140+
user(record, :name) #=> "meg"
141141
142142
# To update the record
143-
user(record, age: 26) #=> {:user, "José", 26}
143+
user(record, age: 26) #=> {:user, "meg", 26}
144144
145145
# Convert a record to a keyword list
146-
user(record) #=> [name: "José", age: 26]
146+
user(record) #=> [name: "meg", age: 26]
147147
148148
By default, Elixir uses the record name as the first element of
149149
the tuple (the tag). But it can be changed to something else:

0 commit comments

Comments
 (0)