Functional programming in Julia
In this recipe, we will demonstrate how to use Julia to achieve functional style programming. We will create a function that takes another function as a parameter and returns a function again. Such an approach could be useful in writing computational code.
Getting ready
For the main part of this recipe, no installation is required.However, we will also show a plot of the processed function using theUnicodePlots.jl
package. In order to install the package, press] key in the package manager type:
(v1.0) pkg>addUnicodePlots
This will install theUnicodePlots.jl
package and all its requirements.
Note
In the GitHub repository for this recipe you will find the commands.txt
file that contains the presented sequence of Julia commands.
How to do it...
To see how functional programming works in Julia, observe the following steps:
- In this recipe, we start by creating a function that generates as its result a new function that is a derivative of the original:
functionderiv(f::Function...