Created
April 17, 2023 03:14
-
-
Save pwc3/5b4c0fd7257b764034ed8d8287165e89 to your computer and use it in GitHub Desktop.
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
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