Chapter 2. Flow and Functional Transformations

We saw the structure of Clojure in Chapter 1. You now can create collections and manipulate them. In this chapter, we are going to see how to make our code come to life. First, we will learn how to control the logic flow, starting with logic tests, then moving on to some basic control flow forms. While we are at it, we will also cover some useful functions that create other functions. Next, we will take a look at destructuring. Destructuring is a process that can pull apart and give names to collection elements that you care about, making them more readable.

After that, we will take a look at the lazy nature of Clojure. In doing so, we will explore the power of lazy evaluation and how it will let us deal with infinite lists. All this will get us ready to explore a very import concept, which is recursion. With recursion, we will look at how the structure of Clojure and functional programming fit together to transform code beautifully. Finally, we will take a look at some fundamental forms in Clojure that are key to shaping data in a functional way.

This chapter is a lot to take in, so don’t get discouraged if it doesn’t click into place at once. Let the examples wash right now. They will soak into a good understanding when we put it all to practice in Part II.

One more thing before we dive in. Let’s talk about some terminology. Sometimes we talk about expressions and sometimes we talk about forms. What exactly do they mean? Are they ...

Get Living Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.