I'm playing around with Scala(z) to learn functionnal programming.
I have a value of type Future[List[Error \/ Double]]
and want to transform it to something with the type Future[[List[Error] \/ List[Double]]
.
The goal is to group the lefts and rights.
I currently have the following:
val foo: Future[List[Error] \/ List[Double]] = {
for {
results <- resultsF
} yield
results.foldLeft(\/[List[Error], List[Double]])({
case (acc, v) if v.isRight => v :: \/-(acc)
case (acc, v) if v.isLeft => v :: -\/(acc)
})
}
However, I get an error on the ::
which is due to the fact that my accumulator is not a list (from the outside) \/[List[Error], List[Double]]
. How should it be done?