Skip to content

Instantly share code, notes, and snippets.

@pwc3
Created April 17, 2023 03:14
Show Gist options
  • Save pwc3/5b4c0fd7257b764034ed8d8287165e89 to your computer and use it in GitHub Desktop.
Save pwc3/5b4c0fd7257b764034ed8d8287165e89 to your computer and use it in GitHub Desktop.
import Foundation
extension Optional {
func unwrap(orThrow error: @autoclosure () -> Error) throws -> Wrapped {
guard let value = self else {
throw error()
}
return value
}
func unwrap(or fallback: Wrapped) -> Wrapped {
guard let value = self else {
return fallback
}
return value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment