-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Clojure Programming Cookbook
By :
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.
This section does not make use of any external library, so you can just start a REPL and be ready.
First, let's see some functions take functional arguments.
Clojure functions such as map and reduce can take functions as arguments.
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 ...