Scala-功能方法-预期的NotInferedA

时间:2018-11-14 16:21:41

标签: scala

我必须代表两个HTML网站内容的字符串。我要删除空格和注释,计算它们之间的Levenshtein距离,并在此基础上决定是否类似。 我创建了函数:

  val removeWhiteSpacesAndHtmlComments: String => String = _.replaceAll("\\s+","\\s").replaceAll("<!--.*?-->","")
  val prepareContents: (String,String) => (String,String) = (s1,s2) => (removeWhiteSpacesAndHtmlComments.apply(s1), removeWhiteSpacesAndHtmlComments(s2))
  val computeLevenshteinDistance:(String,String) => Int = StringUtils.getLevenshteinDistance(_,_)
  val areContentsSimilarEnough: Int => Boolean = _ <= 50

我想将所有这些功能组合成一个流程:

val isHtmlContentChanged: (String,String) => Boolean = prepareContents.tupled andThen computeLevenshteinDistance andThen areContentsSimilarEnough

不幸的是,在computeLevenshteinDistance部分出现了异常:

Type mismatch, expected: (String,String) => NotInferedA, actual: (String,String)=>Int

如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

.tupled添加到computeLevenshteinDistance

Try it out!