有可能重构这个scala代码吗
我有以下功能:有可能重构这个scala代码吗,scala,refactoring,Scala,Refactoring,我有以下功能: def firstFunctionMethod(contextTypeName: String): Parser[FunctionCallExpr] = namespace into { namespaceName => function into { functionName => functionExprParameters(contextTypeName) ~ opt(secondFunctionMetho
def firstFunctionMethod(contextTypeName: String): Parser[FunctionCallExpr] = namespace into {
namespaceName =>
function into {
functionName =>
functionExprParameters(contextTypeName) ~ opt(secondFunctionMethod(getFunctionReturnType(functionName).get)) ^^ {
case args ~ subPath => FunctionCallExpr(namespaceName + functionName, args, subPath)
}
}
}
可能的目标类有10个具有完全相同代码的函数的问题。唯一的变化是firstFunctionMethod和secondFunctionMethod总是不同的
有可能重构它吗?下一个或类似的代码应该适合您 def firstFunctionMethodcontextTypeName:String:Parser[FunctionCallExpr]=FirstFunctionTemplateContextTypeName,secondFunctionMethod def firstFuncTemplatecontextTypeName:String,secFunc:TypeIn=>TypeOut:Parser[FunctionCallExpr]=命名空间到{ 名称空间名称=> 作用于{ functionName=> functionExprParameterscontextTypeName~optsecFuncgetFunctionReturnTypefunctionName.get^^{ case args~subPath=>FunctionCallExprnamespaceName+functionName,args,subPath } }
}这些函数的类型也不同吗?