I am having issues trying to write a method to return a Future[Map[Int,Long]].
I was in some iteration of this getting back a Future[Future[..]]. So I tried the flatMap identity.
Please see below for my code and error messages I am getting now. I am not sure what is going on here at the moment.
def aggregate(permissions: Vector[Permission]): Map[Int, Long]
def calculate(roleProfile: RoleProfile): Future[Map[Int, Long]] = {
val roleIds = roleProfile.roles.map(r => r.id)
db.run(permissionDao.getByRoles(roleIds.toList)).map {
permissions =>
aggregate(permissions)
}
}
def generate(roleGroupId: Int): Future[Map[Int, Long]] = {
for {
roleGroup <- roleGroupService.getById(roleGroupId)
roles <- roleGroupService.getRolesByGroupId(roleGroupId)
} yield {
calculate(RoleProfile(roleGroup.get.id, roles.toSet)) //flatMap identity
}
}
I am getting an error message for method 'calculate':
type mismatch;
[error] found : scala.concurrent.Future[Map[Int,Long]]
[error] required: Map[Int,Long]
[error] calculate(RoleProfile(roleGroup.get.id, roles.toSet)) //flatMap identity
Now if remove the comments for 'flatMap identity' I get this error:
type mismatch;
[error] found : Map[Int,Long] => Map[Int,Long]
[error] required: Map[Int,Long] => scala.concurrent.Future[?]
[error] calculate(RoleProfile(roleGroup.get.id, roles.toSet)) flatMap identity
I'm very confused, how can I get this to return Future[Map[Int, Long]].
And more importantly, what is going on here that I just don't seem to understand. Please break things down if you can much appreciated.