Last active
October 6, 2016 14:16
-
-
Save DevAndArtist/dad641ee833e60b02fd1db2dbb488c6a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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