daily pastebin goal
76%
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public enum Either<L, R> {
  2.     case left(L)
  3.     case right(R)
  4. }
  5.  
  6. extension Either {
  7.  
  8.     public var left: L? {
  9.         switch self {
  10.         case .left(let value): return value
  11.         default: return nil
  12.         }
  13.     }
  14.  
  15.     public var right: R? {
  16.         switch self {
  17.         case .right(let value): return value
  18.         default: return nil
  19.         }
  20.     }
  21.  
  22.     public func either<U>(ifLeft: (L) -> U, ifRight: (R) -> U ) -> U {
  23.         switch self {
  24.         case .left(let value): return ifLeft(value)
  25.         case .right(let value): return ifRight(value)
  26.         }
  27.     }
  28.    
  29. }
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
 
Top