Using functional programming style
In this recipe, we will show you how to define and use anonymous functions and have functions as arguments and return functions. Using the concepts and techniques described here correctly provides higher abstraction.
Getting ready
This section does not make use of any external library, so you can just start a REPL and be ready.
How to do it...
First, let's see some functions take functional arguments.
Functions taking functions as their arguments
Clojure functions such as map and reduce can take functions as arguments.
map
The map function has already been seen in the previous chapters. The map function takes a function as the first argument, applies it to all elements of collection arguments, and returns a lazy sequence.
In the following example, map applies inc to all elements of the collection:
(map inc [1 2 3 4 5]) ;;=> (2 3 4 5 6)
The map function takes an arbitrary number of arguments and returns a lazy sequence. The following code applies +...