SHARE
TWEET

Untitled

a guest Aug 19th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extension Result {
  2.  
  3.    @discardableResult
  4.    func ifFailure(_ f: (Failure) -> Void) -> Result {
  5.        if case let .failure(e) = self { f(e) }
  6.        return self
  7.    }
  8. }
  9.  
  10. extension Result where Failure: OptionSet, Failure == Failure.Element {
  11.    
  12.    @discardableResult
  13.    func ifFailure(contains error: Failure, _ f: () -> Void) -> Result {
  14.        if case let .failure(e) = self,
  15.            e.contains(error) {
  16.                f()
  17.        }
  18.        return self
  19.    }
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top