Anyone can tell me the difference between func _ and func(_) in Scala? I had to override this method:
def validations: List[ValueType => List[FieldError]] = Nil
If I override it with:
val email = new EmailField(this, 255){
override def validations = valUnique _ :: Nil
private def valUnique(email: String): List[FieldError] = {
Nil
}
}
It is ok, while if I override it with:
val email = new EmailField(this, 255){
override def validations = valUnique(_) :: Nil
private def valUnique(email: String): List[FieldError] = {
Nil
}
}
It is not ok. Anyone can me explain why? Thank you very much.
If you wrote it like this:
I'm sure it would tell you you are getting a
String => List[List[FieldError]]
instead of the required type. When an underline is used in place of a parameter (instead of as part of an expression), it is expanded as a function in the immediate outer scope. Specifically,On the other hand,
valUnique _
is just saying "get this method and turn it into a function`, so