Skip to content

Commit 93a1dba

Browse files
committed
Fix linting, deepen the pros
1 parent 004308f commit 93a1dba

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3867,8 +3867,9 @@ defmodule Kernel do
38673867
This macro expects the first argument to be a condition and the second
38683868
argument to be a keyword list. Generally speaking, Elixir developers
38693869
prefer to use pattern matching and guards in function definitions and
3870-
`case/2`. However, `if/2` is valuable for logical expressions that
3871-
cannot be written within the mechanisms found in patterns and guards.
3870+
`case/2`, as they are succinct and precise. However, not all conditions
3871+
can be expressed through patterns and guards, which makes `if/2` a viable
3872+
alternative.
38723873
38733874
Similar to `case/2`, any assignment in the condition will be available
38743875
on both clauses, as well as after the `if` expression.

lib/elixir/pages/getting-started/case-cond-and-if.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ The documentation for the `Kernel` module lists all available guards in its side
6969

7070
## if/unless
7171

72-
7372
`case` builds on pattern matching and guards to destructure and match on certain conditions. However, patterns and guards are limited only to certain expressions which are optimized by the compiler. In many situations, you need to write conditions that go beyond what can be expressed with `case`. For those, `if/2` (and `unless/2`) are useful alternatives:
7473

7574
```elixir
@@ -172,4 +171,4 @@ iex> cond do
172171

173172
## Summing up
174173

175-
We have concluded the introduction to the most fundamental control-flow constructs in Elixir. Generally speaking, Elixir developers prefer pattern matching and guards, using `case` and function definitions (which we will explore in future chapters). When your logic cannot be expressed within patterns and guards, you may consider `if/2`, falling back to `cond/1` when there are several conditions to check.
174+
We have concluded the introduction to the most fundamental control-flow constructs in Elixir. Generally speaking, Elixir developers prefer pattern matching and guards, using `case` and function definitions (which we will explore in future chapters), as they are succinct and precise. When your logic cannot be outlined within patterns and guards, you may consider `if/2`, falling back to `cond/1` when there are several conditions to check.

0 commit comments

Comments
 (0)