Feature request - guard from Swift


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

It looks good.


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


See this topic.


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.