Skip to content

Instantly share code, notes, and snippets.

@westerlund
Last active May 9, 2017 07:18
Show Gist options
  • Save westerlund/1ea6f9a2c975a0b5ed8d11656cc96358 to your computer and use it in GitHub Desktop.
Save westerlund/1ea6f9a2c975a0b5ed8d11656cc96358 to your computer and use it in GitHub Desktop.
borrowed from https://github.com/JohnSundell/Unbox/ to prove a point
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