[swift-evolution] !? operator for ternary conditional unwrapping

Adrian Zubarev adrian.zubarev at devandartist.com
Wed Feb 8 09:07:06 CST 2017

If you need a infix operator that traps, here you have one ;)

infix operator ?! : NilCoalescingPrecedence

func ?! <T>(optional: T?, noreturn: @autoclosure () -> Never) -> T {
   switch optional {
   case .some(let value):
      return value
   case .none:

let x: Int? = nil  

let y: Int = x ?! fatalError("Your message here")

Adrian Zubarev
Sent with Airmail

Am 8. Februar 2017 um 16:00:24, Haravikk via swift-evolution (swift-evolution at swift.org) schrieb:

I say it's a bit of an odd operator since it doesn't actually trap.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170208/d4709b67/attachment.html>

More information about the swift-evolution mailing list