追踪“扩展函数的缺失参数类型”

时间:2017-06-05 12:39:02

标签: scala

我坚持使用代码,每当我尝试运行它时,我都会收到错误:

Error:(37, 66) missing parameter type for expanded function
The argument types of an anonymous function must be fully known. (SLS 8.5)
Expected type was: com.bfg.domain.model.RunnerSnap
  def syncPrices(pair: (RunnerSnap, RunnerChange)): RunnerSnap = {

然而,错误消息让我无法知道需要更改什么才能使其正常工作。

  def syncPrices(pair: (RunnerSnap, RunnerChange)): RunnerSnap = {
    case (cache: RunnerSnap, delta: RunnerChange) =>
      val newHc = if (delta.hc.isEmpty) cache.runnerId.handicap else delta.hc
      val id = RunnerId(delta.id, newHc)
      val prices = MarketRunnerPrices(
        atl = syncPriceVolume(cache.prices.atl, delta.atl),
        atb = syncPriceVolume(cache.prices.atb, delta.atb),
        trd = syncPriceVolume(cache.prices.trd, delta.trd),
        spb = syncPriceVolume(cache.prices.spb, delta.spb),
        spl = syncPriceVolume(cache.prices.spl, delta.spl),

        batb = syncLevelPriceVolume(cache.prices.batb, delta.batb),
        batl = syncLevelPriceVolume(cache.prices.batl, delta.batl),
        bdatb = syncLevelPriceVolume(cache.prices.bdatb, delta.bdatb),
        bdatl = syncLevelPriceVolume(cache.prices.bdatl, delta.bdatl),

        spn = if (delta.spn.isEmpty) cache.prices.spn else delta.spn,
        spf = if (delta.hc.isEmpty) cache.prices.spf else delta.spf,
        ltp = if (delta.hc.isEmpty) cache.prices.ltp else delta.ltp,
        tv = if (delta.hc.isEmpty) cache.prices.tv else delta.tv
      )
      RunnerSnap(id, prices)
  }
  

我的问题是:为什么我会收到此错误以及我需要做什么   更改我的代码以使其按预期工作?

1 个答案:

答案 0 :(得分:1)

您遗失了pair match

def syncPrices(pair: (RunnerSnap, RunnerChange)): RunnerSnap = pair match {
  case (cache: RunnerSnap, delta: RunnerChange) =>
    ...
}