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

feat: ✨ add examples of record pattern matching #88

Merged
merged 4 commits into from
Jun 12, 2024

Conversation

xxKeefer
Copy link
Contributor

@xxKeefer xxKeefer commented Apr 24, 2024

close #56 by adding examples of record destructuring to the tour

Copy link
Member

@lpil lpil left a 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:

  1. let can only be used with single variant custom types
  2. Labels can be used
  3. 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.

@xxKeefer
Copy link
Contributor Author

thanks for the feedback @lpil hopefully this is looking better 👍🏻

@xxKeefer xxKeefer changed the title feat: ✨ add examples of record destructuring feat: ✨ add examples of record pattern matching Apr 29, 2024
Copy link
Member

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

</p>
<p>
It is possible to use underscore <code>_</code> or the spread syntax <code>..</code> to
discard fields that are not required.
Copy link
Member

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.

Copy link
Member

@lpil lpil left a 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

@lpil lpil force-pushed the issue-56_record-destructuring-example branch from 8cef99a to 29f06ba Compare June 12, 2024 13:05
@lpil lpil merged commit 2246bbb into gleam-lang:main Jun 12, 2024
1 check passed
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.

No example of record destructuring in a let assignment
2 participants