 
 }
 
-// From two Results, return one Result of their values or the first failure.
+/**
+ From two results, returns one result wrapping all their values or the first error.
+
+ - parameter resultA: The first result to repackage.
+ - parameter resultB: The second result to repackage.
+ - returns: A result wrapping either a tuple of all the given results' success values, or the first error among them.
+ */
 public func zip<A, B>(_ resultA: Result<A>, _ resultB: Result<B>) -> Result<(A, B)> {
     return resultA.tryMap { a in
         (a, try resultB.value())
     }
 }
 
-// From three Results, return one Result of their values or the first failure.
+/**
+ From three results, returns one result wrapping all their values or the first error.
+ 
+ - parameter resultA: The first result to repackage.
+ - parameter resultB: The second result to repackage.
+ - parameter resultC: The third result to repackage.
+ - returns: A result wrapping either a tuple of all the given results' success values, or the first error among them.
+ */
 public func zip<A, B, C>(_ resultA: Result<A>, _ resultB: Result<B>, _ resultC: Result<C>) -> Result<(A, B, C)> {
     return zip(resultA, resultB).tryMap { a, b in
         (a, b, try resultC.value())
     }
 }
 
-// From four Results, return one Result of their values or the first failure.
+/**
+ From four results, returns one result wrapping all their values or the first error.
+ 
+ - parameter resultA: The first result to repackage.
+ - parameter resultB: The second result to repackage.
+ - parameter resultC: The third result to repackage.
+ - parameter resultD: The fourth result to repackage.
+ - returns: A result wrapping either a tuple of all the given results' success values, or the first error among them.
+ */
 public func zip<A, B, C, D>(_ resultA: Result<A>, _ resultB: Result<B>, _ resultC: Result<C>, _ resultD: Result<D>) -> Result<(A, B, C, D)> {
     return zip(resultA, resultB, resultC).tryMap { a, b, c in
         (a, b, c, try resultD.value())
     }
 }
 
-// From an array of Results, return one Result of an array of their values or the first failure.
+/**
+ From an array of results, returns one result wrapping all their values or the first error.
+ 
+ - parameter results: The array of results to repackage.
+ - returns: A result wrapping either an array of all the given results' success values, or the first error among them.
+ */
 public func zipArray<T>(_ results: [Result<T>]) -> Result<[T]> {
     return results.reduce(Result { [] }) { arrayResult, itemResult in
         arrayResult.tryMap { array in

        }
    }

    // Return a failure if we have one.
    // Otherwise, transform the success value into a new success value.
    public func map<U>(_ transform: (Value) -> U) -> Result<U> {
        return tryMap(transform)
    }

    // The canonical flatMap.
    // Return a failure if we have one.
    // Otherwise, transform the success value into a new success or failure.
    public func flatMap<U>(_ transform: (Value) -> Result<U>) -> Result<U> {
        return tryMap { value in
            try transform(value).value()
        }
    }

    // An error-catching variation on flatMap.
    // Return a failure if we have one.
    // Otherwise, transform the success value into a new success value, or fail if an error is thrown.
    public func tryMap<U>(_ transform: (Value) throws -> U) -> Result<U> {
        return Result<U> {
            try transform(try value())


import Foundation

/**
 A model for a success or failure case.

 This type precisely represents the domain of results of a function call that either returns a value or throws an error.
 
 Result is used by `Promise` to represent success or failure outside the normal flow of synchronous execution.
 
 Result is a functor and a monad; you can map and flatMap.

 - `map` transforms a success value into a new success value, but preserves errors.
 - `flatMap` also preserves errors, but transforms a success value to a new Result, meaning it may produce a new failure.
 - `tryMap` works like `flatMap`, but uses a transformation function that returns or throws.
 */
public enum Result<Value> {

    /// A successful result wrapping a returned value.
    case success(Value)
    /// A failed result wrapping a thrown error.
    case failure(Error)

    /**
     Creates a result by immediately invoking a function that returns or throws.

     - parameter create: A function whose returned value or thrown error becomes wrapped by the result.

     The opposite operation is `value()`.
     */
    public init(create: () throws -> Value) {
        do {
            let value = try create()
