Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public enum Either<L, R> {
- case left(L)
- case right(R)
- }
- extension Either {
- public var left: L? {
- switch self {
- case .left(let value): return value
- default: return nil
- }
- }
- public var right: R? {
- switch self {
- case .right(let value): return value
- default: return nil
- }
- }
- public func either<U>(ifLeft: (L) -> U, ifRight: (R) -> U ) -> U {
- switch self {
- case .left(let value): return ifLeft(value)
- case .right(let value): return ifRight(value)
- }
- }
- }
Add Comment
Please, Sign In to add comment