Clyde Barrow
Clyde Barrow

Reputation: 2102

Scala - functional methods - expected NotInferedA

I have to Strings which represent two html site contents. I want to remove whitespaces and comments, compute Levenshtein distance between them and on that basis I want to decide wether they are similiar or not. I created functions:

  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

I want to combine all those functions into a flow:

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

Unfortunately over the computeLevenshteinDistance part I get exception:

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

How to solve this ?

Upvotes: 0

Views: 364

Answers (1)

Markus Appel
Markus Appel

Reputation: 3238

Add .tupled to computeLevenshteinDistance.

Try it out!

Upvotes: 2

Related Questions