Hi all, sorry if this has been asked before, or I’m just not searching for the right thing on google, but I can’t seem to find a good answer.
Say we have a function
def query(x : String) : Seq[T] = { ... }
and a list of strings we want to process
a,b,......,z
Doing
Query(A), Query(B), .... , Query(Z)
sequentially takes a while to run, (and each query is independent of eachother) so I’d like to run the queries in parallel, and then return the results in one big seq. However, when searching online, it seems like all the examples involving futures are of the form
val af = future{}
val bf = future{}
....
val zf = future{}
for {
a <- af
b <- bf
...
z <- zf
} yield (a ++ b ++ ... ++ z)
But in my case, I’m not always going to have the same string inputs/same number of inputs. So I was wondering if say I had an array or list of the inputs
say Array(a,b,c,…) or List(a,b,c,…,d)
is there a way to have each element computed in parallel, and then joined back together in a yield like statement. Thanks in advance!