Scala Language Higher Order Function

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Remarks

Scala goes to great lengths to treat methods and functions as syntactically identical. But under the hood, they are distinct concepts.

A method is executable code, and has no value representation.

A function is an actual object instance of type Function1 (or a similar type of another arity). Its code is contained in its apply method. Effectively, it simply acts as a value that can be passed around.

Incidentally, the ability to treat functions as values is exactly what is meant by a language having support for higher-order functions. Function instances are Scala's approach to implementing this feature.

An actual higher-order function is a function that either takes a function value as an argument or returns a function value. But in Scala, as all operations are methods, it's more general to think of methods that receive or return function parameters. So map, as defined on Seq might be thought of as a "higher-order function" due to its parameter being a function, but it is not literally a function; it is a method.



Got any Scala Language Question?