     return p.future
 }
 
+/**
+
+    Converts Future<Future<S, E>, E> into Future<S, E>
+
+    :param: fx Future
+
+    :returns: flattened Future
+
+*/
 public func flatten<F: FutureType, IF: FutureType where F.SuccessType == IF, F.ErrorType == IF.ErrorType>(fx: F) -> Future<IF.SuccessType, IF.ErrorType> {
     let p = Promise<IF.SuccessType, IF.ErrorType>()
     

    return p.future
}

public func toDeferred<F: FutureType>(fx: F) -> Deferred<Result<F.SuccessType, F.ErrorType>> {
    let p = PurePromise<Result<F.SuccessType, F.ErrorType>>()
    fx.onComplete(ExecutionContext.DefaultPureOperationContext) {

    return p.future
}

/**

    Creates a new future by applying a function `f` to the success result of this future.

    :param: fx Future
    :param: f Function that will be applied to success result of `fx`
    :param: ec Execution context of `f`

    :returns: a new Future

*/
public func map<F: FutureType, T>(fx: F, f: F.SuccessType -> T)(_ ec: ExecutionContextType) -> Future<T, F.ErrorType> {
    return transform(fx, f, id)(ec)
}

/**

    Creates a new future by applying the 's' function to the successful result of this future, or the 'e' function to the failed result.

    :param: fx Future
    :param: s Function that will be applied to success result of `fx`
    :param: e Function that will be applied to failed result of `fx`
    :param: ec Execution context of `s` and `e` functions

    :returns: a new Future
*/
public func transform<F: FutureType, S, E>(fx: F, s: F.SuccessType -> S, e: F.ErrorType -> E)(_ ec: ExecutionContextType) -> Future<S, E> {
    let p = Promise<S, E>()
    fx.onComplete(ec) {
