I do not know the elevator, but this is a general question. First of all, ::
is the Scala cons operator:
scala> 1 :: 2 :: List(3, 4) res0: List[Int] = List(1, 2, 3, 4)
This means that super.validations
is some sequence, and valMinLen(3, "Link URL must be at least 5 characters") _
is the only value in this list.
It can be seen from the context that in the overridden validations
method they call the super
version and add a preliminary check at the beginning.
This additional check is created by calling valMinLen()
. However, this additional call does not return an element matching the validations
list type, but a function. Instead of adding the value of the function, we explicitly say (adding _
suffix`) that we want to add the function in advance, and not the return value of this function.
A code snippet is worth a thousand words:
scala> def f = 3 f: Int scala> def g = 4 g: Int scala> val listOfInts = List(f, g) listOfInts: List[Int] = List(3, 4) scala> val listOfFunctions = List(f _, g _) listOfFunctions: List[() => Int] = List(<function0>, <function0>)
Compare the type of listOfInts
and listOfFunctions
. I believe the f _
syntax is called a partially applied function in the Scala world.
Tomasz Nurkiewicz
source share