鉴于Scala中的这一代码:
val mapMerge : (Map[VertexId, Factor], Map[VertexId, Factor]) => Map[VertexId, Factor] = (d1, d2) => d1 ++ d2
Run Code Online (Sandbox Code Playgroud)
这可以缩短为:
val mapMerge : (Map[VertexId, Factor], Map[VertexId, Factor]) => Map[VertexId, Factor] = _ ++ _
Run Code Online (Sandbox Code Playgroud)
实际上代码的作用是重命名Map [VertexId,Factor]的operator ++,因此:有没有办法将该运算符赋值给变量?就像在这个想象中的例子一样:
val mapMerge : (Map[VertexId, Factor], Map[VertexId, Factor]) => Map[VertexId, Factor] = Map.++
Run Code Online (Sandbox Code Playgroud)
并且可能使用类型推断它就足够了
val mapMerge = Map[VertexId,Factor].++
Run Code Online (Sandbox Code Playgroud)
谢谢