2015-04-27 148 views
0

我的情況下,域類如下階嵌套的理解與期貨

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修真在getLinkedgetAccountProfile方法的幫助下構造Future域對象列表AccountInfo

回答

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) } 
+0

我可以知道如何處理此流程中的異常嗎? –