Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

tzakian
Copy link
Contributor

@tzakian tzakian commented May 16, 2024

Description

Still a bit of a work in progress, but want to put this up for early eyes/feedback anyone might have.

Test plan

👀

Copy link

vercel bot commented May 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 28, 2024 4:22pm
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview May 28, 2024 4:22pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview May 28, 2024 4:22pm
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview May 28, 2024 4:22pm

@@ -0,0 +1,567 @@
# Pattern Matching

A `match` expression is a powerful control structure that allows you to compare a value against a
Copy link
Contributor

Choose a reason for hiding this comment

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

image

OtherEnum::V(MyEnum::Variant(..))
```

More concisely we have the following grammar for patterns in Move:
Copy link
Contributor

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

Comment on lines +16 to +27
```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
```
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

@ronny-mysten ronny-mysten left a 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.

Co-authored-by: ronny-mysten <118224482+ronny-mysten@users.noreply.github.com>
@tzakian
Copy link
Contributor Author

tzakian commented May 31, 2024

Closing in favor of this PR that adds it to the move-book repo: MystenLabs/move-book#69

@tzakian tzakian closed this May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants