 
   return first
 }
-
-import Dispatch
 
 public func firstDetermined<Value, S: Sequence>(_ deferreds: S, cancelOthers: Bool = false) -> Deferred<Deferred<Value>>
   where S.Iterator.Element == Deferred<Value>

/// - parameter deferreds: an array of `Deferred`
/// - returns: a new `Deferred`

public func combine<Value>(_ deferreds: [Deferred<Value>]) -> Deferred<[Value]>
{
  var combined = [Value]()
  combined.reserveCapacity(deferreds.count)

  let reduced = reduce(deferreds, initial: (), combine: { _, value in combined.append(value) })
  return reduced.map { _ in combined }
}


/// If the reducing function throws an error, the resulting `Deferred` will contain that error.
/// The combined `Deferred` will use the qos from the first element of the input array (unless the input array is empty.)
///
/// - parameter qos: the Quality-of-Service at which the `reduce` operation and its notifications should occur; defaults to the current QoS
/// - parameter deferreds: an array of `Deferred`
/// - parameter combine: a reducing function
/// - returns: a new `Deferred`

public func reduce<T, U>(qos: DispatchQoS = DispatchQoS.current ?? .default, _ deferreds: [Deferred<T>],
                         initial: U, combine: @escaping (U,T) throws -> U) -> Deferred<U>
{
  guard deferreds.isEmpty == false
    else { return Deferred(qos: qos, result: Result.value(initial)) }

  let queue = DispatchQueue(label: "reduce-collection", qos: qos)
  let accumulator = Deferred(queue: queue, result: Result.value(initial))

  let reduced = deferreds.reduce(accumulator) {
