1

I have an array of promises and I need to resolve them all and take a list of the ones that succeeded. As I understand it, I need to use join to do that. However, when I write:

let promises: [Promise<Request>] = /* ... */
let foo = join(promises)

I get a compile time error Cannot invoke 'join' with argument list of type '([Promise<Request>])'

Am I doing something wrong, or is join not working in Swift?

Daniel T.
  • 32,821
  • 6
  • 50
  • 72

1 Answers1

0

Since this question got up-voted, I figured I should post my eventual solution.

First, calling join with an array was accomplished by implementing an apply function from http://www.drivenbycode.com/the-missing-apply-function-in-swift/

func apply<T, U>(fn: (T...) -> U, args: [T]) -> U {
    typealias FunctionType = [T] -> U
    return unsafeBitCast(fn, FunctionType.self)(args)
}

Second, it turned out that join didn't do what I needed anyway. I ended up writing my own function which I called any. Collect array of successful promises

Community
  • 1
  • 1
Daniel T.
  • 32,821
  • 6
  • 50
  • 72