[Discussion]: Deprecate !-Unwrapping of Optionals

I was thinking something more like

func unsafeUnwrap<T>(opt : Optional<T>) -> T {
    switch opt {
        case let .Some(val):
            return val
        default:
             fatalError("Unexpectedly found nil while unwrapping optional value")
    }
}

Bang doesn't go away, it just becomes more obvious that you're making a leap of logic (as it were).

~Robert Widmann

2016/02/29 15:59、davesweeris@mac.com のメッセージ:

···

On Feb 29, 2016, at 2:24 PM, Developer via swift-evolution <swift-evolution@swift.org> wrote:

And for those cases there will be a standard library function or something more obvious than bang to make up for the deprecated operator. Force unwrapping will not go away (that's a terribly unproductive idea), but the goal is to make a dangerous operation more obvious[ly dangerous].

Like this?
enum OptionalUnwrappingError : ErrorType {
    case unexpectedlyFoundNil
}
enum Optional<T> {
    typealias Wrapped = T
    case None
    case Some(Wrapped)
    ...
    func unwrap() throws -> Wrapped {
        switch self {
        case .None: throw OptionalError.unexpectedlyFoundNil
        case .Some(let value): return value
        }
    }
}

It’s hard to get more obvious than the compiler complaining that you haven’t wrapped a throwing function in a try block

- Dave Sweeris