[英]Scala type mismatch: found Future[MyType] required Future[Option[MyType]]
我從API獲取Future[MyType]
。 如何將Future[MyType]
轉換為Future[Option[MyType]]
?
def getApiKey(id: String): Future[Option[MyType]] = Future {
val g: Future[Option[MyType]] = getID(id) // error mismatch
g
}
def getID(id: String): Future[MyType] = {
//return Future[MyType]
}
使用map
:
def getApiKey(id: String): Future[Option[MyType]] = {
getID(id).map(Option(_))
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.