Skip to content

Instantly share code, notes, and snippets.

@wibed
Last active August 17, 2020 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wibed/3898f4c7186e09a90588939cdf588e57 to your computer and use it in GitHub Desktop.
Save wibed/3898f4c7186e09a90588939cdf588e57 to your computer and use it in GitHub Desktop.
/// 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