This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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