Higher-order Functions
Introduction
Martin Odersky1 in his Functional Programming in Scala course illustrates higher-order functions2 with a simple example in Scala. Scala is a modern functional programming language where functions are first-class citizen so they can be used, like any other value, as a parameter and returned as a result.
|
I love the Scala lean syntax–and its syntactic sugars–, but Python and R–my old friends–are also, among other paradigms, functional languages. So how is it possible to perform the same things?
In Python
The syntax is very close–and the results are the same :-). Anonymous functions are called lambda.
|
In R
Mainly the same thing. I’m not an expert in R and maybe there is a way to use the formula notation (~
) instead of the anonymous function notation, but I don’t know.
|
In the next course, he introduces more compact syntax, but this is another story.
-
Martin Odersky has designed the Scala programming language. ↩︎
-
Lecture 2.1 - Higher-Order Functions - École Polytechnique Fédérale de Lausanne | Coursera ↩︎