mplatvoet
09/25/2015, 8:33 AMif-let is a useful construct I think the added value to a language like Kotlin is minimal. For Swift this construct is somewhat a necessity as it actually lacks null/nil in some sense. Every nullable type in Swift is actually an Option type (so with none-some) on which you can pattern match:
switch foo{
case .None:
//
case let a:
//
}
(since 2.0 you can match nil for readability sake). If-let is the easy way to unwrap the value of that type. In Kotlin we don't need to unwrap, we just need to check whether something is null, autocasting does the rest. And yes I do realize there are a couple of cases/snippets that really can leverage an if-let construct, e.g.:
fun foo() : Foo? = ....
...
if (let a = foo())
//got foo
else
//no foo :-)
I think the gain here is minimal, but maybe I'm missing important use-cases? What do you think?