Search code examples
scalafold

Scala: Iterating over a Future of list of tuples containing lists as well. Need a final result of Future of tuple


I have a val assume

val a: Future[List[(List[Case_Class], List[Case_Class])]] = //some method call

In my tuple, there are two lists, say

listA = List[Case_Class] and listB = List[Case_Class]. 

Both the lists are having two elements at a time. What I need is applying some logic(ex: fold) to my val 'a' so as to achieve

Future[(List(Case_Class), List(Case_Class))]

What should be the logic that I must apply?


Solution

  • Something like

    a.map(_.unzip match { case (x, y) => (x.flatten, y.flatten) })