How to convert List[Task[List[Header]]] type to Task[List[Header]] in scala .
I have a method which returns Task[List[Header]] and calling dor multiple times it becomes List[Task[List[Header]]]
You can use Task.sequence, and then map flatten over the resulting list of lists, e.g:
val res: List[Task[List[Header]]] = ...
Task.sequence(res).map(_.flatten)
If you need parallel execution over the results, you can take a look on Task.gather.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With