First-class functions

The next functions that we'll look at are repeatedly and fn. The repeatedly function takes a second function and returns an infinite (or n length if supplied) lazy sequence of calls to this second function. This is the first encounter with a function that can take another function. We'll also encounter functions that return other functions. Described as first-class functions, these fall out of the lambda calculus and are the central features of functional programming.

As such, we need to wrap our previous (rand 35) call in another function. The fn function is one of Clojure's core functions and produces an anonymous, unnamed function. We can now supply this function to repeatedly.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.46.92