Sequences Without End

As we saw in the last chapter, the useful thing about sequences is that they are abstract. Instead of being a linked list or an array or some other definite kind of collection, a seq captures the idea of a sequential collection. A sequence is a thing that will give you the first value when you call first, and another sequence—representing the remaining contents—when you call rest or next. That is pretty much it.

Now consider that sequences are defined in terms of function calls. You can get the lead item in your sequence by calling the first function and a sequence representing the remaining items by calling another function, either next or (more likely) rest. We’ve seen how we can take advantage of the function-driven nature ...

Get Getting 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.