【发布时间】:2020-07-14 11:43:55
【问题描述】:
我有一个方法,需要String 类型作为参数:
type Identity = String
case class RequireSmth(param: Identity) extends Something
现在我以更复杂的顺序调用此方法:
createMe(as[List])(arg =>{ parse(RequireSmth(getAction(name, surname).map(bool => getData(surname, bool).id))) })
Parse 看起来像:
def parse(ob: Something)
地点:
def getAction(name: String, surname: String): Future[Boolean] = {
someObject.get(name).map(_.getSomething(surname).isPossibleToTake.getOrElse(false)) //someObject is defined in constructor and does not matter here
}
def getData: (String, Boolean) => MyObject = {
case ("Doe", true) => possible
case _ => notPossible
}
MyObject、possible 和 notPossible 定义:
case class MyObject(id : String, name: String, surname: String)
val possible = MyObject( id = "ok", name ="John", surname = "Doe")
val notPossible = MyObject( id = "not ok", name ="John", surname = "Doe")
问题是,当我调用RequireSmth 方法时出现错误:
type mismatch;
found: scala.concurrent.Future[String]
required: com.my.smth.Identity (which expands to) String
如何解决这个问题以返回Identity(或String)而不是Future[String]?
【问题讨论】: