Skip to content

Commit

Permalink
finish sentence in pattern matching.md (#1087)
Browse files Browse the repository at this point in the history
also add a short explanation about overlaping
match arms
  • Loading branch information
savente93 authored Sep 30, 2023
1 parent f19db58 commit 5708b37
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cookbook/pattern_matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,20 @@ The equivalent in `if-else` statements would be:
}
```
As you can see you can also use command expressions in match statements (in this case used with `|`). Also notice the `_` case at the end, this is called the default arm and is used.
As you can see you can also use command expressions in match statements (in this case used with `|`). Also notice the `_` case at the end, this is called the default arm and is used in case none of the other patterns match. Note also that in the case that cases overlap the first matching pattern will be used (just like with `if-else` statements):
```nu
[yellow green] | each {|c|
match $c {
"green" => "fundamental"
"yellow" | "green" => "vibrant"
}
}
───┬────────────
0 │ vibrant
1 │ funamental
───┴────────────
```
## Pattern matching on types
Expand Down

0 comments on commit 5708b37

Please sign in to comment.