Hydra
Hydra copied to clipboard
zip() function as global function (outside Promise class)
What I was wishing for:
all(promiseA,promiseB).then { resultA, resultB in
}
Based on the docs it would have to be
all(promiseA,promiseB).then { result in
let resultA = result[0]
let resultB = result[1]
}
or
Promise<Void>.zip(promiseA, promiseB).then { resultA, resultB in
}
Any thoughts?
Actually
let (resultA,resultB) = await(Promise<Void>.zip(
promiseA,
promiseB
))
print(resultA)
print(resultB)
isn't so bad - except for the Promise<Void>.
Wondering if that could be turned into just Promise.zip though.
@tcurdt wouldn't your suggestion require n number of all method declaration, one for each different number of tuple elements/parameters?
I suppose it would require that. At least I am not aware that exploding on the in is possible with Swift (yet) - because then it could be just like this:
all(promiseA,promiseB).then { (resultA, resultB) in
}
That's said - other libraries just do the pragmatic thing in such a case and cover the e.g. n<10 cases.
If zip static functions changed to global function like all, we no longer necessary type Promise<Void> to use zip.
Promise class is not adapted to Sequence protocol, so not happen ambiguous compile error with zip(sequence1, sequence2) function even if Hydra implement zip global functions.
@malcommac What do you think about it?
@r-plus I think its the better choice; I've changed it here: https://github.com/malcommac/Hydra/commit/b9568eff1dc799d7c25a211d529ef1058780b787.