Skip to content

Instantly share code, notes, and snippets.

@rnapier rnapier/result.swift
Last active Aug 29, 2015

What would you like to do?
The ever-important Result type (without methods)
enum Result<A> {
case Success(Box<A>)
case Failure(NSError)
// Due to current swift limitations, we have to include this Box in Result.
// Swift cannot handle an enum with multiple associated data (A, NSError) where one is of unknown size (A)
final class Box<T> {
let unbox: T
init(_ value: T) { self.unbox = value }
extension Result: Printable {
var description: String {
switch self {
case Success(let box): return "Success: \(box.unbox)"
case Failure(let err): return "Failure: \(err.description)"
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.