I have a hashmap map: Map[A, Seq[B]]
and I want to call a future function (that returns Future[Either[Error, Unit]]
) for each B
in my map.
For example, given the following function def fooFunc(hashMap: Map[A, Seq[B]]): Future[Either[Error, Unit]]
I tried something like
def fooFunc(hashMap: Map[A, Seq[B]]): Future[Either[Error, Unit]] = {
val result = for {
_ <- hashMap.map(entry =>
entry._2.map( value =>
Future.sequence(futureFunc(value, entry._1)).liftF
)
)
} yield ()
result.value
}
which gives the compile error Type mismatch, expected: NotInferedM[Future[NotInferedA]], actual: [Future[Either[Error, Unit]]]
This is my first time dealing with futures and iterating over hashmap, so I'm confused how to exactly go about this and deal with the Iterable. Any tips would be appreciated