Greg
Greg

Reputation: 11542

Missing Parameter for Anonymous Function

The compiler is complaining about the code below, saying: missing parameter type for expanded function

I'm not sure how to make it happy. Any ideas?

def unwrapMap(m: Map[_, _]) =
  { (vcType: String) =>
    m.map {
      case (k, v) => {
        (k,v)  // echo the map for sample purposes
      }
    }.toMap
  }

Upvotes: 0

Views: 82

Answers (1)

Alois Cochard
Alois Cochard

Reputation: 9862

You should give concrete types to your Map instead of discarding them with '_':

  def unwrapMap[A, B](m: Map[A, B]) =
  { (vcType: String) =>
    m.map {
      case (k, v) => {
        (k,v)  // echo the map for sample purposes
      }
    }.toMap
  }

That way the compiler can infer the type of the anonymous function created into the method '.map'.

Upvotes: 1

Related Questions