Last active
May 9, 2017 07:18
-
-
Save westerlund/1ea6f9a2c975a0b5ed8d11656cc96358 to your computer and use it in GitHub Desktop.
borrowed from https://github.com/JohnSundell/Unbox/ to prove a point
This file contains 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
func orThrow<E: Error>(_ errorClosure: @autoclosure () -> E) throws -> Wrapped { | |
guard let value = self else { | |
throw errorClosure() | |
} | |
return value | |
} | |
// usage | |
orThrow(UnboxError.invalidData) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment