David Rodrigues
08/13/2022, 10:06 PMreturn
a certain value based on a condition, and I'd like to propose this feature:
return x if != null
// <and/or>
return x if user != null
Same for break
or continue
Other examples:
return x if >= 5
return x if is User
return x if x + 1 >= 5
And maybe:
x = 5 if x < 2
jw
08/13/2022, 10:19 PMif (user != null) return x
and it means you're aware of the conditional before seeing the action.David Rodrigues
08/13/2022, 10:22 PMFleshgrinder
08/14/2022, 6:42 AMreturn if (x is User) x else null
hfhbd
08/14/2022, 6:43 AMFleshgrinder
08/14/2022, 6:47 AMKlitos Kyriacou
08/15/2022, 8:37 AMWhat does it return if the condition is not true? Null? Unit?I understood the OP as meaning that it doesn't return if it's not true. It carries on, same as
if (x is User) return x
without an else
part.
I'm neither for nor against this proposition, but found it interesting as similar syntax appears in various other languages.