Is there a more idiomatic way to achieve the resul...
# coroutines
j
Is there a more idiomatic way to achieve the result of asynchronously loading a bunch of file data from a list of paths? I've been using this:
Copy code
val data: List<MyDataClass> = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
    filePaths.map { path ->
        async {
            path.inputStream().use {
                // Read in file data as instance of MyDataClass
            }
        }
    }.awaitAll()
}
y
You could use arrow fx!
Copy code
val data = filePaths.parMap(<http://Dispatchers.IO|Dispatchers.IO>) {
  path.inputStream().use { ... }
}