Skip to content

Commit aaaa921

Browse files
authored
Fix pages code examples (#15663)
1 parent e20ca7e commit aaaa921

11 files changed

Lines changed: 23 additions & 22 deletions

File tree

‎lib/elixir/pages/anti-patterns/macro-anti-patterns.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,11 @@ If you really need to define modules dynamically, you can do so via meta-program
380380
defmodule MyMacro do
381381
defmacro call_examples(parts) do
382382
for part <- parts do
383+
module = Module.concat(OtherModule, part)
384+
383385
quote do
384386
# This builds OtherModule.Foo at compile-time
385-
OtherModule.unquote(part).example()
387+
unquote(module).example()
386388
end
387389
end
388390
end

‎lib/elixir/pages/anti-patterns/process-anti-patterns.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ defmodule Counter do
279279

280280
@doc "Bumps the value of the given counter."
281281
def bump(name \\ __MODULE__, value) do
282-
Agent.get_and_update(fn state -> {state, value + state} end)
282+
Agent.get_and_update(name, fn state -> {state, value + state} end)
283283
end
284284
end
285285
```

‎lib/elixir/pages/cheatsheets/enum-cheat.cheatmd‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -689,14 +689,14 @@ iex> Enum.map_join(cart, ", ", & &1.fruit)
689689
"apple, banana, orange"
690690
```
691691

692-
### [`intersperse(enum, separator \\ "")`](`Enum.intersperse/2`)
692+
### [`intersperse(enum, separator)`](`Enum.intersperse/2`)
693693

694694
```elixir
695695
iex> Enum.intersperse(["apple", "banana", "orange"], ", ")
696696
["apple", ", ", "banana", ", ", "orange"]
697697
```
698698

699-
### [`map_intersperse(enum, separator \\ "", mapper)`](`Enum.map_intersperse/3`)
699+
### [`map_intersperse(enum, separator, mapper)`](`Enum.map_intersperse/3`)
700700

701701
```elixir
702702
iex> Enum.map_intersperse(cart, ", ", & &1.fruit)
@@ -976,7 +976,7 @@ iex> Enum.chunk_every(cart, 2)
976976
]
977977
```
978978

979-
### [`chunk_every(enum, count, step, leftover \\ [])`](`Enum.chunk_every/2`)
979+
### [`chunk_every(enum, count, step, leftover \\ [])`](`Enum.chunk_every/4`)
980980

981981
```elixir
982982
iex> Enum.chunk_every(cart, 2, 2, [:elements, :to_complete])
@@ -1019,7 +1019,7 @@ iex> Enum.zip(fruits, counts)
10191019

10201020
See `Enum.zip/1` for zipping many collections at once.
10211021

1022-
### [`zip_with(enum1, enum2, fun)`](`Enum.zip_with/2`)
1022+
### [`zip_with(enum1, enum2, fun)`](`Enum.zip_with/3`)
10231023

10241024
```elixir
10251025
iex> fruits = ["apple", "banana", "orange"]

‎lib/elixir/pages/getting-started/introduction.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ For now, let's start by running `iex` (or `iex.bat` if you are on Windows PowerS
2929
Open up `iex` and type the following expressions:
3030

3131
```elixir
32-
Erlang/OTP 26 [64-bit] [smp:2:2] [...]
32+
Erlang/OTP 27 [64-bit] [smp:2:2] [...]
3333

3434
Interactive Elixir - press Ctrl+C to exit
3535
iex(1)> 40 + 2

‎lib/elixir/pages/mix-and-otp/docs-tests-and-with.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ defmodule KV.Command do
181181
end
182182
```
183183

184-
Before we implement this function, let's change our server to start using our new `parse/1` and `run/1` functions. Remember, our `read_line/1` function was also crashing when the client closed the socket, so let's take the opportunity to fix it, too. Open up `lib/kv/server.ex` and replace the existing server definition:
184+
Before we implement this function, let's change our server to start using our new `parse/1` and `run/2` functions. Remember, our `read_line/1` function was also crashing when the client closed the socket, so let's take the opportunity to fix it, too. Open up `lib/kv/server.ex` and replace the existing server definition:
185185

186186
```elixir
187187
defp serve(socket) do
@@ -289,7 +289,7 @@ You can read more about `with/1` in our documentation.
289289

290290
## Running commands
291291

292-
The last step is to implement `KV.Command.run/1` to run the parsed commands on top of buckets. Its implementation is shown below:
292+
The last step is to implement `KV.Command.run/2` to run the parsed commands on top of buckets. Its implementation is shown below:
293293

294294
```elixir
295295
@doc """
@@ -354,7 +354,7 @@ Our server functionality is almost complete. Only tests are missing.
354354

355355
## Integration tests
356356

357-
`KV.Command.run/1`'s implementation is sending commands directly to the `KV` module, which is using a local registry to name processes. This means if we have two tests sending messages to the same bucket, our tests will conflict with each other (and likely fail). One might think this would be a reason to use mocks and other strategies to keep our tests isolated, but such techniques often make our testing environment too distant from how our code actually runs in production, and you may end-up with bugs lurking.
357+
`KV.Command.run/2`'s implementation is sending commands directly to the `KV` module, which is using a local registry to name processes. This means if we have two tests sending messages to the same bucket, our tests will conflict with each other (and likely fail). One might think this would be a reason to use mocks and other strategies to keep our tests isolated, but such techniques often make our testing environment too distant from how our code actually runs in production, and you may end-up with bugs lurking.
358358

359359
Luckily, there is a technique that we have been using throughout this guide that would be equally applicable here: it is ok to rely on the local registry as long as each test uses unique names. Using a combination of the test module and test name is more than enough to guarantee that.
360360

‎lib/elixir/pages/mix-and-otp/dynamic-supervisor.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Given our buckets can already be supervised, you may be thinking to start them a
7272

7373
```elixir
7474
children = [
75-
{Registry, name: KV, keys: :unique}
75+
{Registry, name: KV, keys: :unique},
7676
{KV.Bucket, name: {:via, Registry, {KV, "shopping"}}}
7777
]
7878
```
@@ -223,7 +223,7 @@ Not only that, as you create new buckets on the terminal, you should see new pro
223223
224224
```elixir
225225
iex> KV.create_bucket("shopping")
226-
#PID<0.89.0>
226+
{:ok, #PID<0.89.0>}
227227
```
228228
229229
We will leave it up to you to further explore what Observer provides. Note you can double-click any process in the supervision tree to retrieve more information about it, as well as right-click a process to send "a kill signal", a perfect way to emulate failures and see if your supervisor reacts as expected.

‎lib/elixir/pages/mix-and-otp/genservers.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ Open up `test/kv/server_test.exs` and add this new test:
300300

301301
The test creates a bucket and subscribes to it. Then it opens up another TCP connection to send commands. For each command sent, we expect the subscribed socket to receive a message.
302302

303-
To make the test pass, we need to change `KV.Command` to parse the new `SUBSCRIBE` command and then run it. Open up `lib/kv/commands.ex` and then first change the `parse/1` definition to the following:
303+
To make the test pass, we need to change `KV.Command` to parse the new `SUBSCRIBE` command and then run it. Open up `lib/kv/command.ex` and then first change the `parse/1` definition to the following:
304304

305305
```elixir
306306
def parse(line) do

‎lib/elixir/pages/mix-and-otp/task-and-gen-tcp.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ Let's change `start/2` in `lib/kv.ex` once more, to add the task supervisor to o
221221
end
222222
```
223223

224-
We'll now start a `Task.Supervisor` process with name `KV.TaskSupervisor`. Keep in mind that the order children are started matters. For example, the acceptor must come last because, if it comes first, it means our application can start accepting requests before the `Task.Supervisor` is running or before we can locate buckets. Shutting down an application will also stop the children in reverse order, guaranteeing a clean termination.
224+
We'll now start a `Task.Supervisor` process with name `KV.ServerSupervisor`. Keep in mind that the order children are started matters. For example, the acceptor must come last because, if it comes first, it means our application can start accepting requests before the `Task.Supervisor` is running or before we can locate buckets. Shutting down an application will also stop the children in reverse order, guaranteeing a clean termination.
225225

226226
Now we need to change `loop_acceptor/1` to use `Task.Supervisor` to serve each request:
227227

‎lib/elixir/pages/references/compatibility-and-deprecations.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Version | Deprecated feature | Replaced by (ava
122122
[v1.15] | `Regex.regex?/1` | `Kernel.is_struct/2` (`Kernel.is_struct(term, Regex)`) (v1.11)
123123
[v1.15] | `Logger.warn/2` | `Logger.warning/2` (v1.11)
124124
[v1.14] | `use Bitwise` | `import Bitwise` (v1.0)
125-
[v1.14] | `~~~/1` | `bnot/2` (v1.0)
125+
[v1.14] | `~~~/1` | `bnot/1` (v1.0)
126126
[v1.14] | `Application.get_env/3` and similar in module body | `Application.compile_env/3` (v1.10)
127127
[v1.14] | Compiled patterns in `String.starts_with?/2` | Pass a list of strings instead (v1.0)
128128
[v1.14] | `Mix.Tasks.Xref.calls/1` | Compilation tracers (outlined in `Code`) (v1.10)

‎lib/elixir/pages/references/gradual-set-theoretic-types.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ You can represent all _proper_ lists as `list()`, which also includes the empty
8181

8282
You can also specify the type of the list element as argument. For example, `list(integer())` represents the values `[]` and `[1, 2, 3]`, but not `[1, "two", 3]`.
8383

84-
Internally, Elixir represents the type `list(a)` as the union two distinct types, `empty_list()` and `not_empty_list(a)`. In other words, `list(integer())` is equivalent to `empty_list() or non_empty_list(integer())`.
84+
Internally, Elixir represents the type `list(a)` as the union two distinct types, `empty_list()` and `non_empty_list(a)`. In other words, `list(integer())` is equivalent to `empty_list() or non_empty_list(integer())`.
8585

8686
#### Improper lists
8787

0 commit comments

Comments
 (0)