Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions exercises/concept/guessing-game/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,21 @@ pub fn describe(number: Int) -> String {
// No compiler error
```

Multiple __literal patterns__ can be matched in one clause using the `|` to separate between each literal value. Only one guard can be added to a case:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the stuff about literal patterns please, all patterns use literal syntax, and they are not values between the |s

Copy link
Contributor Author

@JP-Go JP-Go May 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. Changed it. Could you review again?


```gleam
pub fn describe(number: Int) -> String {
let yell = True
case number {
0 -> "Zero"
3 | 5 -> "One of the first odd prime numbers"
2 | 4 | 6 | 8 if !yell -> "One of the even numbers less than 10"
i if i % 2 == 0 && yell -> "[Yelling] I'm telling you! It's a even nunber"
i if i < 0 -> "Negative number"
_ -> "Positive number"
}
}
// No compiler error
```

Case expressions will test a value against each pattern from top to bottom, until it finds a matching pattern and executes the logic associated with that pattern. The order of patterns matters!