2017-08-07 6 views
0

私はPlayframeworkとSlickの非同期機能を使用していますが、理解のために将来の戻りメソッドの結果とインラインで作業する方法はわかりません。今、私はそれを、このようなやり方をやってる:理解のためのScala結果を渡すときに未来の作成を避ける方法

def getWordDefinitions(checkedWordsIds: List[CheckedWord]) : Future[List[WordDefinition]] = { 
    val ids = checkedWordsIds.map(_.wordId) 

    for { 
    translations <- translationRepo.findByIds(ids) 
    translations2 <- Future(sortByHowManyChecks(checkedWordsIds, translations)) 
    wordDefinitionsList <- Future(translations2.map(translation => WordDefinition(translation._2.english, translation._2.translation))) 
    } yield { 
    wordDefinitionsList 
    } 
} 

私はtranslations2 <オフ取り払う方法を知りたい - 未来を()、ほか(未来を返された別に、またはラップ機能)機能に移動します。 sortByHowManyChecks関数はサードパーティのライブラリにあるMap [Long、TranslationObject]を返します。あなたは、単にそれをこのように書くことができますあなたの場合は

答えて

0

def getWordDefinitions(checkedWordsIds: List[CheckedWord]) : Future[List[WordDefinition]] = { 
    val ids = checkedWordsIds.map(_.wordId) 

    for { 
    translations <- translationRepo.findByIds(ids) 
    translations2 = sortByHowManyChecks(checkedWordsIds, translations) 
    } yield translations2.map(translation => WordDefinition(translation._2.english, translation._2.translation)) 
} 
0

あなたがすべてで利回りを使用していないについてどう思いますか?すべての返品陳述書が正しいかどうかはわかりません。

def getWordDefinitions(checkedWordsIds: List[CheckedWord]) : Future[List[WordDefinition]] = { 
    val ids = checkedWordsIds.map(_.wordId) 

    translationRepo.findByIds(ids) 
    .map(translations => sortByHowManyChecks(checkedWordsIds, translations)) 
    .map(translation => WordDefinition(translation._2.english, translation._2.translation)) 
} 
関連する問題