Skip to Main Content
Programming Clojure, 3rd Edition
book

Programming Clojure, 3rd Edition

by Alex Miller, Stuart Halloway, Aaron Bedra
February 2018
Intermediate to advanced content levelIntermediate to advanced
304 pages
7h 11m
English
Pragmatic Bookshelf
Content preview from Programming Clojure, 3rd Edition

Lazier Than Lazy

Clojure’s lazy sequences are a great form of laziness at the language level. As a programmer, you can be even lazier by finding solutions that don’t require explicit sequence manipulation at all. You can often combine existing sequence functions to solve a problem, without having to get your hands dirty at the level of recur or lazy sequences.

As an example of this, let’s implement several solutions to the following problem. You are given a sequence of coin-toss results, where heads is :h and tails is :t:

 [:h :t :t :h :h :h]

How many times in the sequence does heads come up twice in a row? In the previous example, the answer is two. Toss 3 and toss 4 are both heads, and toss 4 and toss 5 are both heads.

The sequence of ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Kotlin

Programming Kotlin

Venkat Subramaniam
Getting Clojure

Getting Clojure

Russ Olsen

Publisher Resources

ISBN: 9781680505719Errata Page