[swift-evolution] Allow let binding of non-optionals

Jacob Bandes-Storch jtbandes at gmail.com
Thu Jan 7 13:06:34 CST 2016


On Thu, Jan 7, 2016 at 11:02 AM, Joe Groff <jgroff at apple.com> wrote:

>
> On Jan 7, 2016, at 10:59 AM, Jacob Bandes-Storch via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>         *do let* value2 = somethingNonOptional()
>
>
> 'case let' already works like this, by declaring a pattern 'let a' that
> unconditionally matches anything.
>
> -Joe
>

You learn something new every day on this list!

This effectively solves the problems I've had. However, I think the
resulting code is misleading, because "if case let" or just "case let" look
like conditional expressions, when really they aren't.

    if case let x = somethingNonOptional() {
        // use x, *unconditionally*
    } // x out of scope now

I think "do let" would improve readability considerably...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160107/050e8f92/attachment.html>


More information about the swift-evolution mailing list