[swift-evolution] Brainstorming: Optional sugar inferred map
Thorsten Seitz
tseitz42 at icloud.com
Tue Feb 16 00:35:55 CST 2016
> Am 16.02.2016 um 05:52 schrieb Paul Ossenbruggen via swift-evolution <swift-evolution at swift.org>:
>
> I guess if auto closure could take a parameter you could do something like this:
>
> @warn_unused_result
> public func ??<T>(optional: T?, @autoclosure defaultValue: (result : T) throws -> T) rethrows -> T {
> return optional != nil ? optional! : try defaultValue(result: optional!)
> }
This will always throw an exception as you are force unwrapping the optional in both branches of the ternary, i.e. also in the branch which is used when it is nil.
-Thorsten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160216/9ec4da5b/attachment.html>
More information about the swift-evolution
mailing list