Allow case
condition in return statement
#4092
Labels
request
Requests to resolve a particular developer problem
case
condition in return statement
#4092
Trying to refactor a simple function that validates a
Uri
:I have followed my instincts and wrote this code using patters:
and found out that I can't use
case
conditions anywhere outside anif
. Furthermore, when I changed the code to use anif
condition I found out that I can only use a singlecase
condition in theif
.I got this to work with a
switch
and a single pattern:But this approach requires me to explicitly return true and have a default false case, when all I want is to just return a bool result of "this variable did(n't) match this pattern".
In my opinion it would be useful and intuitive to be able to use
case
conditions outside ofif
and to chain multiple conditions withcase
. This might be two separate issues, but this was my thought process when trying to refactor this function.The text was updated successfully, but these errors were encountered: