Last active
August 17, 2020 09:51
-
-
Save wibed/3898f4c7186e09a90588939cdf588e57 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
/// checks a value is not nil else throws a custom error | |
public extension Future where Expectation: OptionalType { | |
func unwrapnil(or error: @autoclosure @escaping () -> Error) -> | |
Future<Expectation.WrappedType> { | |
return map(to: Expectation.WrappedType.self) { optional in | |
guard optional.wrapped != nil else { | |
throw error() | |
} | |
return optional.wrapped! | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment