async icon indicating copy to clipboard operation
async copied to clipboard

add and that takes one and two future

Open pedantix opened this issue 7 years ago • 4 comments

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.

pedantix avatar Feb 21 '18 18:02 pedantix

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

gperdomor avatar Feb 21 '18 18:02 gperdomor

okie

pedantix avatar Feb 21 '18 20:02 pedantix

Just an FYI, you can do

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

0xTim avatar Feb 22 '18 12:02 0xTim

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

calebkleveter avatar Feb 22 '18 15:02 calebkleveter