-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
feat: ✨ add examples of record pattern matching #88
feat: ✨ add examples of record pattern matching #88
Conversation
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.
Wonderful, thank you.
There's no such thing as destructuring in Gleam, that's a JavaScript term. In Gleam we pattern match.
Pattern matching has already been explained, so we don't need to explain what it is, but we do want to explain that:
let
can only be used with single variant custom types- Labels can be used
- The
..
spread operator can be used to match on only a portion of the fields.
It might be good to show _
but I don't think we need to explain it as it has been covered by previous lessons.
src/content/chapter3_data_types/lesson04_record_destructuring/code.gleam
Outdated
Show resolved
Hide resolved
src/content/chapter3_data_types/lesson04_record_destructuring/code.gleam
Outdated
Show resolved
Hide resolved
thanks for the feedback @lpil hopefully this is looking better 👍🏻 |
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.
Using labels when pattern matching isn't covered here. Let's get that in as matching on fields by label is something folks coming from other ecosystems might think is always what happens, rather than it being positional when no labels are used.
src/content/chapter3_data_types/lesson04_record_pattern_matching/en.html
Outdated
Show resolved
Hide resolved
</p> | ||
<p> | ||
It is possible to use underscore <code>_</code> or the spread syntax <code>..</code> to | ||
discard fields that are not required. |
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.
It would be good to explain the difference between them here, and show the difference in the code example.
src/content/chapter3_data_types/lesson04_record_pattern_matching/en.html
Outdated
Show resolved
Hide resolved
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.
Wonderful! And thank you for waiting as I catch up with all my notifications
use correct terms, clean up code example, explain everything that need to be gleam-lang#56
Co-authored-by: Louis Pilfold <[email protected]>
8cef99a
to
29f06ba
Compare
close #56 by adding examples of record destructuring to the tour