Skip to content

Commit

Permalink
Fix linting, deepen the pros
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed May 17, 2024
1 parent 004308f commit 93a1dba
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/elixir/lib/kernel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3867,8 +3867,9 @@ defmodule Kernel do
This macro expects the first argument to be a condition and the second
argument to be a keyword list. Generally speaking, Elixir developers
prefer to use pattern matching and guards in function definitions and
`case/2`. However, `if/2` is valuable for logical expressions that
cannot be written within the mechanisms found in patterns and guards.
`case/2`, as they are succinct and precise. However, not all conditions
can be expressed through patterns and guards, which makes `if/2` a viable
alternative.
Similar to `case/2`, any assignment in the condition will be available
on both clauses, as well as after the `if` expression.
Expand Down
3 changes: 1 addition & 2 deletions lib/elixir/pages/getting-started/case-cond-and-if.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ The documentation for the `Kernel` module lists all available guards in its side

## if/unless


`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:

```elixir
Expand Down Expand Up @@ -172,4 +171,4 @@ iex> cond do

## Summing up

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.
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 comments on commit 93a1dba

Please sign in to comment.