     
     case success(Value)
     case failure(Error)
+}
+
+extension Result {
     
     /// Creates a succesful result with an associated value.
-    public init(_ value: Value) { self = .success(value) }
+    public init(value: Value) { self = .success(value) }
     
     /// Creates a result with an associated error.
-    public init(_ error: Error) { self = .failure(error) }
+    public init(error: Error) { self = .failure(error) }
     
     /// Optional value, returned when Self is .success.
     public var value: Value? {
-     
+        
         switch self {
         case .success(let value): return value
         case .failure:            return nil

//
//  Created by Wyatt McBain on 10/21/16.
//  Copyright © 2016 ZX Ventures. All rights reserved.
//

import Foundation

        }
    }
}

extension Result {
    
    /// Returns a new Result by mapping success values using a transform
    /// or re-wraps error into failure.
    @discardableResult
    public func map<T>(_ transform: (Value) -> T) -> Result<T> {
        
        return flatMap { .success(transform($0)) }
    }
    
    /// Returns the Result of applying a transform to a success value or
    /// the re-wrapped error into failure.
    @discardableResult
    public func flatMap<T>(_ transform: (Value) -> Result<T>) -> Result<T> {
        
        switch self {
        case .success(let value): return transform(value)
        case .failure(let error): return .failure(error)
        }
    }
    
    /// Returns a new Result by mapping failure errors using a transform
    /// or re-wraps values into success.
    @discardableResult
    public func mapError(_ transform: (Error) -> Error) -> Result<Value> {
        
        return flatMapError { .failure(transform($0)) }
    }
    
    /// Returns the Result of applying a transform to a failure error or
    /// the re-wrapped value into success.
    @discardableResult
    public func flatMapError(_ transform: (Error) -> Result<Value>) -> Result<Value> {
        
        switch self {
        case .success(let value): return .success(value)
        case .failure(let error): return transform(error)
        }
    }
}
