Skip to content

Instantly share code, notes, and snippets.

@owensd
Created August 22, 2014 18:57
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 owensd/4f203c03f350c8999fa3 to your computer and use it in GitHub Desktop.
Save owensd/4f203c03f350c8999fa3 to your computer and use it in GitHub Desktop.
//
// 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