Feature request - guard from Swift


#1

Hi everyone. Can you add guard keyword as in Swift?

It looks good.


#2

What does the guard keyword do, or what functionality adds?


#3

See this topic.


#4

Why create this topic which the same as another?

Also as I understand from https://www.hackingwithswift.com/new-syntax-swift-2-guard Swift needs this because there if construct is not an expression and doesn’t return the value.

All their examples can be implemented as val variable = if (condition) { value } else { return } or if condition is “not null” the shortcut val variable = value ?: { return }

Also all this unwrapping business only applicable to Optional wrapper, which replaced by nullable types in Kotlin. Kotlin smart to know that type of the local variable in not nullable, which is equivalent to unwrapped value in Swift.