The way a higher-order function accepts a lambda expression is by means of a function parameter whose data type is a function type.
A function type consists of:
A comma-delimited list of parameter types, wrapped in parentheses, where the types can either be concrete or can reference generic types (e.g.,
T
) declared on the function (<T>
)An arrow (
->
)The return type
Then, the higher-order function can call invoke()
on the function type parameter
to execute the lambda expression, supplying any needed parameters and
consuming any result.
Here, hasMatch()
does the same thing as any()
, returning true
if
any of the items in the list results in a true
result from the
function type.
You can learn more about this in:
Tags: