May 2018
Beginner to intermediate
290 pages
6h 43m
English
Since so much of Clojure programming revolves around creating, combining, and using functions, it’s unsurprising that the language provides a fair number of functions aimed at easing the job.
Take, for example, the apply function. It tackles the surprisingly common situation where you have a function and the arguments that you want to call that function with in a collection. In other words, instead of having this:
| | (+ 1 2 3 4) ; Gives you 10. |
what if you had the function (+ in this case) and the arguments, like this:
| | (def the-function +) |
| | (def args [1 2 3 4]) |
Enter apply. You supply a function and a collection of arguments, and apply will call that function with the arguments, returning the result. Armed with apply ...
Read now
Unlock full access