Hydra icon indicating copy to clipboard operation
Hydra copied to clipboard

zip() function as global function (outside Promise class)

Open tcurdt opened this issue 6 years ago • 5 comments

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?

tcurdt avatar Aug 22 '17 20:08 tcurdt

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 avatar Aug 22 '17 20:08 tcurdt

@tcurdt wouldn't your suggestion require n number of all method declaration, one for each different number of tuple elements/parameters?

dalu93 avatar Sep 04 '17 10:09 dalu93

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.

tcurdt avatar Sep 04 '17 11:09 tcurdt

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 avatar Dec 09 '17 08:12 r-plus

@r-plus I think its the better choice; I've changed it here: https://github.com/malcommac/Hydra/commit/b9568eff1dc799d7c25a211d529ef1058780b787.

malcommac avatar Dec 16 '17 09:12 malcommac