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

add and that takes one and two future #72

Open
wants to merge 1 commit into
base: beta
Choose a base branch
from

Conversation

pedantix
Copy link

This PR is to add the "and" syntactic sugar to the future structure.

Motivations:

Often times when working with vapor we have to get futures from multiple places such as body content, and database connections. Joining these together to work with them in Map chaining is nice syntactic sugar.

Limitations:

It seems that tuples can be destructured into arguments according to the compiler, the systactic sugar is nice, but not as nice as I would like.

Acctual

var futureT = Future(t)
var futureS = Future(s)

futureT.and(futureS).map(to: V.self) { tAndS in

 return ///
} 

Desired

var futureT = Future(t)
var futureS = Future(s)

futureT.and(futureS).map(to: V.self) { t, s in

 return ///
} 

Future Thoughts:

It would be nice if generics could handle Type lists, however, I think this beyond the scope of what swift 4 can do at the moment as such making a generic that can handle variadic arguments is beyond the scope of this work. I could definitely be wrong and there could be a way to hand N amount of futures in which case, lets do it.

@gperdomor
Copy link
Member

If this is not accepted here please add to the new https://github.com/vapor-community/async-extensions repo :D

@pedantix
Copy link
Author

okie

@0xTim
Copy link
Member

0xTim commented Feb 22, 2018

Just an FYI, you can do

return map(to: V.self, futureT, futureS) { t, s in
 return ///
} 

@calebkleveter
Copy link
Member

@0xTim Yes, there is that option available, but you can't add it onto a future chain, which is where .and will come in.

@tanner0101 tanner0101 self-assigned this Feb 23, 2018
@tanner0101 tanner0101 added this to Backlog in Vapor 3 Feb 26, 2018
@tanner0101 tanner0101 removed this from Backlog in Vapor 3 Mar 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

5 participants