Skip to content

Instantly share code, notes, and snippets.

@DevAndArtist
Last active October 6, 2016 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DevAndArtist/dad641ee833e60b02fd1db2dbb488c6a to your computer and use it in GitHub Desktop.
Save DevAndArtist/dad641ee833e60b02fd1db2dbb488c6a to your computer and use it in GitHub Desktop.
//
// 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