[swift-evolution] [Pitch] Introducing the "Unwrap or Die" operator to the standard library

Ben Cohen ben_cohen at apple.com
Wed Jun 28 20:49:52 CDT 2017


> On Jun 28, 2017, at 6:32 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
> 
>  the reason why a function would return nil _are intended to be obvious, per the design rationale given in Swift project documents_.

The reason .last returns nil is obvious. But it doesn’t tell you anything about why the array itself should be non-empty at this point in the code.

> I do not believe that "array must not be empty" or "array guaranteed non-empty" is such an example, and I cannot myself imagine another scenario where it would make such a difference.


As the screener of a non-zero number of radars resulting from unwrapped nils, I would certainly appreciate more use of guard let x = x else { fatalError(“explanation”) } and hope that !! would encourage it.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170628/73d996e4/attachment.html>


More information about the swift-evolution mailing list