Eduardo
Eduardo

Reputation: 8392

Function equals as default value for a function in Scala

I have the following method:

def foo[B](fn: (B,B) => Boolean): Unit = {
  // do something       
}

Is there a way to provide a default value of equals to the parameter fn?

I have tried

def foo[B](fn: (B,B) => Boolean = ==): Unit = ...

but it fails. (I have also tried ==[B], equals[B], B.equals, etc. but none work)

Upvotes: 2

Views: 69

Answers (1)

Eduardo
Eduardo

Reputation: 8392

I have found that:

def foo[B](fn: (B,B) => Boolean = (a:B, b:B) => a == b)

works.

I have also re-learnt that a method and a function are not the same thing.

Upvotes: 4

Related Questions