Skip to content

Instantly share code, notes, and snippets.

@owensd owensd/Either.swift Secret
Created Aug 22, 2014

Embed
What would you like to do?
//
// Either.swift
// MemoryInvestigation
//
// Created by David Owens II on 8/22/14.
// Copyright (c) 2014 Kiad Software. All rights reserved.
//
import Foundation
public enum Either<T, U> {
case Left(Box<T>)
case Right(Box<U>)
init (left: T) {
self = .Left(Box(left))
}
init (right: U) {
self = .Right(Box(right))
}
public var left: T? {
switch self {
case let .Left(box): return box.value
default: return nil
}
}
public var right: U? {
switch self {
case let .Right(box): return box.value
default: return nil
}
}
}
public final class Box<T> {
let value: T
init(_ value: T) { self.value = value }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.