<@U0B8SM5FX>: Though I do think `if-let` is a usef...
# language-proposals
m
@alexfacciorusso: Though I do think
if-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:
Copy code
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.:
Copy code
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?