我知道我可以解开
Future[Future[Seq]] => Future[Seq]
使用flatMap功能
但是如何获得以下映射?
Future[Seq[Future[Seq]]] => Future[Seq[Seq]]
答案 0 :(得分:4)
geocoder.geocode({
'address': document.getElementById('addressTo').value
}, function(results, status) {
var location = results[0].geometry.location;
poi
if (status == google.maps.GeocoderStatus.OK) {
calculateAndDisplayRoute(directionsService, directionsDisplay, pointA, pointB);
}
会将Future.sequence
更改为Seq[Future[...]]
那么,这样的话:Future[Seq[...]]
也许吧?
答案 1 :(得分:0)
这对我来说就像魔术:
implicit class RichFutureSeqFutures[A](futureSeqFutures: Future[Seq[Future[A]]]) {
def flattenInner: Future[Seq[A]] = {
futureSeqFutures flatMap {Future.collect(_)}
}
}