我的案例域类如下
case class Account(randomId: String, accounts: List[String]) // for each of accounts i need to get AccountProfiles.
case class AccountProfiles(actId: String, profiles: List[String], additionalInfo: Map[String, String], ......)
case class AccountInfo(id: String, profiles:List[String]) // for each of AccountProfiles I need to construct AccountInfo
我的访问层实现签名以提取上面的域类,如下所示
getLinked(): Future[Account]
getAccountProfile(actId: String): Future[AccountProfiles]
在for
和Future
方法的帮助下,我可以AccountInfo
理解构建getLinked
getAccountProfile
域对象列表吗?
答案 0 :(得分:0)
是的,你可以。我认为这是您正在寻找的假设AccountProfiles.actId和AccountInfo.id应该是等效的。
for {
account <- getLinked()
profiles <- Future.sequence(account.accounts map { id => getAccountProfile(id) })
} yield profiles map { p => AccountInfo(p.actId, p.profiles) }