Match Statement Enhancements
Match Binds
We should do as Rust and other languages and support the ability to bind the result of the expression given to a match statement so that there is no requirement to manually store a temporary value via let
.
match ${git::branch}
case ""; echo No branch found
case _ @ result; echo Found $result
end
We may even want to make it possible to elide the '_' on the above expression:
case @ result; echo Found $result
Conditional Checks
We should also support a means of performing an extra in-line conditional check on a given case. Perhaps the ?
operator would make that easier to read? Or should we use the standard 'if'?
match ${git::branch}
case @ result if exists $result; echo Found $result
case "master" if test -z $other; echo Found master branch and $other
end
match ${git::branch}
case @ result ? exists $result; echo Found $result
case "master" ? test -z $other; echo Found master branch and $other
end