extended definition
An anonymous function is defined in a more detailed and complete form as
(a: A, b: B, ...) => function body
eg.
(a: String, b: String) => a ++ b
inferred types
if the context provides the necessary information (for example, when a higher-order function expects a certain signature for its function arguments), you can omit parameter types, since
(a, b, ...) => function body
eg.
val l = List(1, 2, 3)
placeholder syntax
Finally, you can use a shorter form if your parameters are used once in each and in the same order that you declare them as the body of the function, as
_ ++ _
Each _ is a placeholder for function arguments
eg.
filesMatching argument is a function of type String => Boolean , so you can use
_.endsWith(query) // equivalent to (s: String) => s.endsWith(query) _.contains(query) // equivalent to (s: String) => s.contains(query) _.matches(query) // equivalent to (s: String) => s.matches(query)
source share