Skip to content
Merged
Changes from 2 commits
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
6 changes: 4 additions & 2 deletions src/doc/book/if-let.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
% if let

`if let` allows you to combine `if` and `let` together to reduce the overhead
of certain kinds of pattern matches.
`if let` allows us to match [patterns][patterns] within the condition of an [if][if].
As a consequence, we reduce the overhead of certain kinds of [pattern][patterns] matches
Copy link
Contributor

Choose a reason for hiding this comment

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

After thinking about it more, I'm not a huge fan of the word "consequence" here since it usually describes the results of an action, and there's not really an action here. What about:

if let allows us to reduce...

or

This feature allows to reduce...

or

This allows us to reduce...

or something else. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about this? I'd rather avoid using allow twice like that.

if let permits pattern matching within the condition of an if statement.
This allows us to reduce the overhead of certain kinds of [pattern][patterns] matches
and express them in a more convenient way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds great :)

and express them in a more convenient way.

For example, let’s say we have some sort of `Option<T>`. We want to call a function
on it if it’s `Some<T>`, but do nothing if it’s `None`. That looks like this:
Expand Down Expand Up @@ -80,3 +81,4 @@ while let Some(x) = v.pop() {
```

[patterns]: patterns.html
[if]: if.html