Repository navigation
Add pattern matching - #8590
Merged
Merged
Add pattern matching#8590
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #8590 +/- ##
==========================================
- Coverage 68.56% 68.45% -0.11%
==========================================
Files 624 628 +4
Lines 100844 101551 +707
==========================================
+ Hits 69143 69517 +374
- Misses 31701 32034 +333
|
Contributor
|
This |
This was referenced Mar 25, 2023
sholderbach
pushed a commit
that referenced
this pull request
Mar 26, 2023
Should close #8616. Related to #8590. # Description With the new builtin `match` command introduced in the `rust` source in #8590, there is no need to have a custom `match` in the standard library. This PR removes the `match` command from `std.nu` and the associated test. # User-Facing Changes Users can not access `match` from `std.nu`. # Tests + Formatting ``` nu crates/nu-utils/standard_library/tests.nu --path crates/nu-utils/standard_library/ out+err> /dev/null; ($env.LAST_EXIT_CODE == 0) ``` gives `true` # After Submitting ``` $nothing ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This adds
matchand basic pattern matching.An example:
Like the recent changes to
ifto allow it to be used as an expression,matchcan also be used as an expression. This allows you to assign the result to a variable, eg)let xyz = match ...I've also included a short-hand pattern for matching records, as I think it might help when doing a lot of record patterns:
{$foo}which is equivalent to{foo: $foo}.There are still missing components, so consider this the first step in full pattern matching support. Currently missing:
|in Rust)User-Facing Changes
[see above]
Tests + Formatting
Don't forget to add tests that cover your changes.
Make sure you've run and fixed any issues with these commands:
cargo fmt --all -- --checkto check standard code formatting (cargo fmt --allapplies these changes)cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collectto check that you're using the standard code stylecargo test --workspaceto check that all tests passAfter Submitting
If your PR had any user-facing changes, update the documentation after the PR is merged, if necessary. This will help us keep the docs up to date.