From 5708b3752cf48e0c66d2b900e25af46a62a88ffe Mon Sep 17 00:00:00 2001 From: Sam Vente Date: Sun, 1 Oct 2023 00:12:52 +0200 Subject: [PATCH] finish sentence in pattern matching.md (#1087) also add a short explanation about overlaping match arms --- cookbook/pattern_matching.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cookbook/pattern_matching.md b/cookbook/pattern_matching.md index 974181e3227..7dafcfa17ba 100644 --- a/cookbook/pattern_matching.md +++ b/cookbook/pattern_matching.md @@ -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