Cómo aplanar una Lista de Futuros en Scala


Quiero tomar este val:

val f = List(Future(1), Future(2), Future(3))

Realizar alguna operación en él (estaba pensando aplanar)

f.flatten

Y obtener este resultado

scala> f.flatten = List(1,2,3)

Si el método aplanar no es apropiado aquí, está bien. Mientras llegue al resultado.

Gracias!

Author: mikejones1477, 2014-11-03

1 answers

Future.sequence toma un List[Future[T]] y devuelve un Future[List[T]].

Puedes hacer

Future.sequence(f) 

Y luego use map o onComplete para acceder a la lista de valores.

 57
Author: Gabriele Petronella,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-20 06:46:54