Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tcurdt opened this issue Aug 22, 2017 · 5 comments
Open

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

tcurdt opened this issue Aug 22, 2017 · 5 comments
Assignees

Comments

@tcurdt
Copy link

tcurdt commented Aug 22, 2017

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
Copy link
Author

tcurdt commented Aug 22, 2017

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.

@dalu93
Copy link

dalu93 commented Sep 4, 2017

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

@tcurdt
Copy link
Author

tcurdt commented Sep 4, 2017

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.

@r-plus
Copy link
Contributor

r-plus commented Dec 9, 2017

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?

@malcommac
Copy link
Owner

@r-plus I think its the better choice; I've changed it here: b9568ef.

@malcommac malcommac changed the title nicer all zip() function as global function (outside Promise class) Dec 16, 2017
@malcommac malcommac self-assigned this Dec 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants