-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kotlin 'when' conditional operator equivalent in dart #1509
Comments
The Kotlin when (e) {
(computedExpression) -> /* equality test with non-constant value */
99, 100, 101 -> /* multiple patterns */
in 10..25 -> /*range pattern */
!in 10..20 -> /* not in range */
is String -> /* type match */
!is String -> /* negative type match */
x.isEven -> /* boolean test */
} It has implicit break between cases (no fallthrough), and allows a variable declaration in the switch expression: when (var x = something) {
is String -> print(x)
else -> print("$x")
} which is in scope in the rest of the A |
It would also be great to make the result of the when clause assignable to a variable, return, etc. |
Moving to the /langauge repo, which is the main tracker for language evolution |
Isn't this a duplicate of #27? |
Yes, that appears to be the case, @munificent ? (Part of the reason for moving was to ensure things weren't duplicated, so thanks for the headsup @rodrigost23 ) |
It's always hard to decide which language issues are duplicates. If the request is just some kind of multi-way branching expression, then, yeah. But if @karthickr95 is specifically requesting syntax very close to Kotlin's then maybe not. In this case, though, I think it's similar enough to close as a duplicate. |
Need a kotlin like 'when' conditional operator.
Need a optional break statement and when like concise syntax, because it is less boilerplate and like a modern language. And a when or switch expression statement.
The text was updated successfully, but these errors were encountered: