Skip to content

Add example for pattern matching on options #17120

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

Merged
merged 5 commits into from
Feb 22, 2021

Conversation

konsumlamm
Copy link
Contributor

@konsumlamm konsumlamm commented Feb 20, 2021

Follow-up to #17036. This PR adds an example for pattern matching on options. It uses code-block, since fusion isn't bundled anymore (see #16925). If there is a way to turn this into a runnableExamples, please let me know.

@timotheecour
Copy link
Member

If there is a way to turn this into a runnableExamples, please let me know

when true:
  {.experimental: "caseStmtMacros".}
  when (compiles do: import fusion/matching):
    case some(42)
    of Some(@a):
      assert a == 42
    of None():
      assert false
    Some(Some(None())) := some(some(none(int)))

Copy link
Member

@timotheecour timotheecour left a comment

Choose a reason for hiding this comment

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

LGTM after final nits

@Araq Araq merged commit 05711d9 into nim-lang:devel Feb 22, 2021
@konsumlamm konsumlamm deleted the options-matching branch February 23, 2021 12:07
ringabout pushed a commit to ringabout/Nim that referenced this pull request Mar 22, 2021
* Add example for pattern matching on options

* Use code-block

* Apply suggestions

* Use block comments

* Fix example
ardek66 pushed a commit to ardek66/Nim that referenced this pull request Mar 26, 2021
* Add example for pattern matching on options

* Use code-block

* Apply suggestions

* Use block comments

* Fix example
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.

4 participants