1

I wrote a function which returns a function based on the String argument it receives. The code looks as follow:

def getFunction(str:String) : Map[String, String] => String={
    val s = str.charAt(0).toString()
    s matches {
      case "x" => (arg:Map[String, String]) => arg("random")
      case _ =>(arg:Map[String, String]) => arg("")
    }
  }

This is giving a compilation exception

Description Resource    Path    Location    Type
missing parameter type for expanded function The argument types of an anonymous function must be fully known. (SLS 8.5) Expected type was: String   line 9 Scala Problem.

I looked into: The argument types of an anonymous function must be fully known. (SLS 8.5).

But could understand the solution. Can anyone explain what is wrong with above code.

Thanks

Community
  • 1
  • 1
Alok
  • 1,374
  • 3
  • 18
  • 44
  • 2
    The only thing that seems incorrect about your function is that you use `matches` (regex pattern matching, returns boolean) function instead of `match` keyword (structural pattern matching). – Dmitry Kuskov Sep 06 '16 at 09:57
  • Oops .. Thanks .. It worked :) – Alok Sep 06 '16 at 11:39

0 Answers0