Scala: Type missing parameter type for expanded function The argument types of an anonymous function must be fully known. (SLS 8.5)

久未见 提交于 2021-02-08 07:35:19

问题


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

来源:https://stackoverflow.com/questions/39345561/scala-type-missing-parameter-type-for-expanded-function-the-argument-types-of-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!