 
 import typealias Foundation.NSTimeInterval
 
+/**
+
+    Applies the side-effecting function to the result of this deferred,
+    and returns a new deferred with the result of this deferred
+
+    :param: dx Deferred
+    :param: f side-effecting function that will be applied to result of `dx`
+    :param: ec execution context of `f` function
+
+    :returns: a new Deferred
+
+*/
 public func andThen<D: DeferredType>(dx: D, f: D.Element -> Void)(_ ec: ExecutionContextType) -> Deferred<D.Element> {
     let p = PurePromise<D.Element>()
     dx.onComplete(ec) { value in

    }(ec)
}

public func reduce<S: SequenceType, T where S.Generator.Element: DeferredType>(dxs: S, initial: T, combine: (T, S.Generator.Element.Element) -> T)(_ ec: ExecutionContextType) -> Deferred<T> {
    return reduce(dxs, Deferred(initial)) { acc, defValue in
        flatMap(defValue) { value in

    return p.deferred
}

/**

    Stops the current thread, until value of `dx` becomes available

    :param: dx Deferred

    :returns: value of deferred

*/
public func forced<D: DeferredType>(dx: D) -> D.Element {
    return forced(dx, NSTimeInterval.infinity)!
}

/**

    Stops the currend thread, and wait for `inverval` seconds until value of `dx` becoms available

    :param: dx Deferred
    :param: inverval number of seconds to wait

    :returns: Value of deferred or nil if it hasn't become available yet

*/
public func forced<D: DeferredType>(dx: D, interval: NSTimeInterval) -> D.Element? {
    return await(interval) { completion in
        dx.onComplete(ExecutionContext.DefaultPureOperationContext, completion)
