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

Add example for single variant record let structuring #127

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@ pub type Fish {
Jellyfish(name: String, jiggly: Bool)
}

pub type IceCream {
IceCream(flavour: String)
}

pub fn main() {
let lucy = Starfish("Lucy", "Pink")
let favourite_ice_cream = IceCream("strawberry")

case lucy {
Starfish(_, favourite_color) -> io.debug(favourite_color)
Jellyfish(name, ..) -> io.debug(name)
}

// if the custom type has a single variant you can
// destructure it using `let` instead of a case expression!
let IceCream(flavour) = favourite_ice_cream
io.debug(flavour)
}
Loading