-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[move][docs] Add section on pattern matching to Move book #17776
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
3 Ignored Deployments
|
acd3e54
to
034247d
Compare
c732ebf
to
bcf0213
Compare
bcf0213
to
a71fa02
Compare
a71fa02
to
9a6705c
Compare
@@ -0,0 +1,567 @@ | |||
# Pattern Matching | |||
|
|||
A `match` expression is a powerful control structure that allows you to compare a value against a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
OtherEnum::V(MyEnum::Variant(..)) | ||
``` | ||
|
||
More concisely we have the following grammar for patterns in Move: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should really collect all the grammar somewhere one day
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
```move | ||
fun run(x: u64): u64 { | ||
match (x) { | ||
1 => 2, | ||
2 => 3, | ||
x => x, | ||
} | ||
} | ||
|
||
run(1); // returns 2 | ||
run(2); // returns 3 | ||
run(3); // returns 3 | ||
run(0); // returns 0 | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favor of a "flashy" first example. If I end up here, I want the csug description: show me all the usage in 1-2 code examples with all the behavior, then take the time to explain. That way if I'm looking for something quick, it's right here at the top of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it, let me think about what a good example like that might be up here :)
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
e344398
to
023efc1
Compare
023efc1
to
d4035a7
Compare
034247d
to
72a51df
Compare
d4035a7
to
2088886
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Tim! Approving to carry forward.
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
external-crates/move/documentation/book/src/control-flow/pattern-matching.md
Outdated
Show resolved
Hide resolved
Co-authored-by: ronny-mysten <[email protected]>
Closing in favor of this PR that adds it to the move-book repo: MystenLabs/move-book#69 |
Description
Still a bit of a work in progress, but want to put this up for early eyes/feedback anyone might have.
Test plan
👀