Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//
// UnwrapOrTrap.swift
//
infix operator ?! : NilCoalescingPrecedence
/// Performs a nil-coalescing operation, returning the wrapped value of an
/// `Optional` instance or uses the rhs function to stop the program.
///
/// - Parameters:
/// - optional: An optional value.
/// - noreturn: A function to stop the programm.
func ?!<T>(optional: T?, noreturn: @autoclosure () -> Never) -> T {
switch optional {
case .some(let value):
return value
case .none:
noreturn()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment