Clojure
The Essential Reference
Renzo Borgatti
  • MEAP began December 2016
  • Publication in December 2018 (estimated)
  • ISBN 9781617293580
  • 625 pages (estimated)
  • printed in black & white

The Clojure standard library is a treasure trove of functions and macros that have been battle-tested over the years to solve the most challenging programming problems. Knowing what's available in the standard library not only liberates programmers from mundane tasks like connecting to data sources, parsing XML, dealing with numbers but also more advanced problems like handling concurrency and parallelism. Having a deep knowledge of the Clojure standard library helps you solve problems quickly and more efficiently.

Clojure: The Essential Reference is an extensive reference to the standard library but it doesn't read as a dull list of functions. In addition to providing clear explanations for each topic, this guide is full of real-world examples, links, and background information. The book approaches difficult topics by illustrating them in a readable and pleasant way, using visual structure to emphasize the essential information. The book is designed to be used as a reference, but each function provides an interesting reading on its own, offering insight into functional and general programming. By using this reference, you will be able to make the most idiomatic and efficient choice while developing a Clojure application.

Table of Contents detailed table of contents

Part 1: Introduction

1. Know Your Tools

1.1. Why should I care about the Standard Library?

1.2. Aren’t specifications just plain boring?

1.3. The different versions of Clojure

1.4. The Clojure Standard Library

1.5. Making Your Development Life Easier

1.6. The problem of fragmented information

1.7. The well kept secret of the Clojure Ninja

1.8. The perfect companion book

1.9. Summary

Part 2: Fundamentals

2. Creating and manipulating functions

2.1. Function definition

2.1.1. defn and defn-

2.1.2. fn

2.1.3. fn*

2.2. Higher order functions

2.2.1. fnil

2.2.2. comp

2.2.3. complement

2.2.4. constantly

2.2.5. identity

2.2.6. juxt

2.2.7. memfn

2.2.8. partial

2.2.9. every-pred

2.2.10. some-fn

2.3. Threading macros

2.4. ->

2.5. ->>

2.6. as->

2.7. cond->

2.8. cond->>

2.9. some->

2.10. some->>

2.11. Function execution

2.11.1. apply

2.11.2. memoize

2.11.3. trampoline

3. Basic Constructs

3.1. Lexical Binding

3.1.1. let and let*

3.1.2. if-let, when-let, if-some and when-some

3.1.3. letfn and letfn*

3.2. Boolean Operators

3.2.1. not

3.2.2. and, or

3.3. Conditional Branching

3.3.1. if, if-not, when and when-not

3.3.2. cond

3.3.3. condp

3.3.4. case and case*

3.4. Iteration and loops

3.4.1. loop, recur and loop*

3.4.2. range

3.4.3. for

3.5. A Glimpse of Collection Processing

3.5.1. first, second and last

3.5.2. map and map-indexed

3.5.3. filter and remove

3.5.4. reduce and reductions

4. Creating and inspecting macros

4.1. defmacro

4.2. macroexpand, macroexpand-1 and macroexpand-all

4.3. quote

4.4. gensym

4.5. definline

4.6. destructure

4.7. clojure.template/apply-template

4.8. clojure.template/do-template

5. Operations on Numbers

5.1. +, -, * and /

5.2. inc and dec

5.3. quot, rem and mod

5.4. max and min

5.5. max-key and min-key

5.6. rand and rand-int

5.7. with-precision

5.8. +', -', *', inc' and dec'

5.9. unchecked-add, unchecked-subtract, unchecked-multiply, unchecked-inc, unchecked-dec and unchecked-negate

5.10. unchecked-add-int, unchecked-add-int, unchecked-subtract-int, unchecked-multiply-int, unchecked-divide-int, unchecked-inc-int, unchecked-dec-int, unchecked-negate-int and unchecked-remainder-int

6. Comparison and Equality

6.1. = (equal) and not= (not equal)

6.2. = (double equal)

6.3. < (less than), > (more than), <= (less than or equal) ( and >= (more than or equal)

6.4. compare

6.5. identical?

6.6. clojure.data/diff

Part 3: Data Structures

7. Reducers and Transducers

7.1. Reducers

7.1.1. fold

7.1.2. reducer and folder

7.1.3. monoid

7.1.4. foldcat, cat and append!

7.2. Transducers

7.2.1. transduce

7.2.2. eduction

7.2.3. completing

7.2.4. cat

7.3. reduced, reduced?, ensure-reduced, unreduced

8. Collections

8.1. Basics

8.1.1. into

8.1.2. count

8.1.3. nth

8.1.4. empty

8.1.5. every?, not-every?, some and not-any?

8.1.6. empty? and not-empty

8.2. Polymorphic

8.2.1. conj

8.2.2. get

8.2.3. contains?

8.3. General purpose

8.3.1. rand-nth

8.3.2. shuffle

8.3.3. random-sample

8.3.4. frequencies

8.3.5. sort and sort-by

8.3.6. group-by

8.3.7. partition, partition-all and partition-by

8.3.8. flatten

8.3.9. distinct, dedupe and distinct?

8.3.10. replace

8.3.11. reverse

9. Sequential Generation

9.1. Sequential Types

9.1.1. seq and sequence

9.1.2. rseq

9.1.3. seque

9.2. Abstract Generators

9.2.1. repeatedly

9.2.2. iterate

9.2.3. repeat and cycle

9.3. Other Generators

9.3.1. lazy-seq

9.3.2. tree-seq

9.3.3. file-seq

9.3.4. xml-seq

9.3.5. re-seq

9.3.6. line-seq

9.3.7. resultset-seq

9.3.8. iterator-seq and enumeration-seq

9.3.9. concat and lazy-cat

10. Sequential Processing

10.1. rest, next, fnext, nnext, ffirst, nfirst and butlast

10.2. drop, drop-while, drop-last, take, take-while, take-last, nthrest, nthnext

10.3. keep and keep-indexed

10.4. mapcat

10.5. interleave

10.6. interpose

10.7. take-nth

10.8. split-at and split-with

10.9. subseq and rsubseq

10.10. when-first

10.11. chunk, chunk-cons, chunk-first, chunk-rest, chunk-next, chunk-buffer and chunk-append

11. Maps

11.1. Creating

11.1.1. hash-map

11.1.2. array-map

11.1.3. sorted-map and sorted-map-by

11.1.4. create-struct, defstruct, struct-map, struct and accessor

11.1.5. zipmap

11.2. Accessing

11.2.1. keys and vals

11.2.2. find, key and val

11.2.3. select-keys and get-in

11.3. Processing

11.3.1. assoc, assoc-in and dissoc

11.3.2. update and update-in

11.3.3. merge and merge-with

11.3.4. reduce-kv

11.4. Map utilities

11.4.1. clojure.walk/keywordize-keys and clojure.walk/stringify-keys

11.4.2. clojure.set/rename-keys

11.4.3. clojure.set/map-invert

12. Vectors

12.1. vector

12.2. vec

12.3. peek and pop

12.4. vector-of

12.5. mapv

12.6. filterv

12.7. subvec

13. Sets

13.1. hash-set

13.2. set

13.3. sorted-set and sorted-set-by

13.4. disj

13.5. union, difference and intersection

13.6. union, difference and intersection

13.7. select, index, rename, join and project

14. Other Functions

14.1. Strings and Regular Expressions

14.1.1. str

14.1.2. join

14.1.3. replace, replace-first, re-quote-replacement

14.1.4. subs, split and split-lines

14.1.5. trim, triml, trimr, trim-newline

14.1.6. escape, char-name-string, char-escape-string

14.1.7. lower-case, upper-case, capitalize

14.1.8. index-of, last-index-of

14.1.9. blank?, ends-with?, starts-with?, includes?

14.1.10. re-pattern, re-matcher, re-groups, re-seq, re-matches, re-find

14.2. Formatting and Printing

14.2.1. format, printf and cl-format

14.2.2. pr, prn, pr-str, prn-str, print, println, print-str, println-str

14.2.3. pprint, pp, write and print-table

14.2.4. print-method, print-dup and print-ctor

14.2.5. slurp and spit

14.3. Classes and Hierarchies

14.3.1. Type checking

14.3.2. gen-class and gen-interface

14.3.3. reify

14.3.4. deftype and deftype*

14.3.5. proxy, get-proxy-class, construct-proxy, init-proxy, proxy-mappings, proxy-super and update-proxy

14.3.6. defprotocol satisfies? defrecord extend, extend-protocol, extend-type, extends? and extenders

14.3.7. defmulti, defmethod, methods, get-method, remove-method, remove-all-methods, prefer-method and prefers

14.4. Vars and Namespaces

14.4.1. def, declare and defonce

14.4.2. alter-var-root, binding, with-local-vars and with-redefs, var-get, var-set, set!, set-validator! and get-validator

14.4.3. var, intern, find-var, clojure.repl/dir-fn and clojure.repl/dir, bound? and thread-bound?

14.4.4. meta, with-meta, vary-meta, alter-meta! and reset-meta!

14.4.5. ns, create-ns in-ns namespace

14.4.6. ns-name, ns-aliases, ns-map, ns-interns, ns-publics, ns-refers and ns-imports the-ns ns-unalias ns-unmap remove-ns

14.4.7. find-ns all-ns resolve and ns-resolve loaded-libs

14.5. Evaluation

14.5.1. eval, read, compile read-string

14.5.2. load load-file load-reader load-string

14.5.3. clojure.edn/read clojure.edn/read-string default-data-readers clojure.main/load-script

14.6. Java Interoperation

14.6.1. . .. doto new set!

14.6.2. bean, clojure.reflect/reflect, typename, resolve-class, flag-descriptors, do-reflect and type-reflect

14.6.3. make-array, object-array, boolean-array, byte-array, short-array, char-array, int-array, long-array, float-array and double-array, aclone, to-array, to-array-2d and into-array

14.6.4. aget, aset, aset-boolean, aset-byte, aset-short, aset-char, aset-int, aset-long, aset-float and aset-double alength, amap, areduce

14.6.5. booleans, bytes, shorts, chars, ints, longs, floats and doubles

14.6.6. try, catch, finally, throw, ex-info and ex-data, Throwable→map

14.7. Concurrency

14.7.1. future, future-call, future-done?, future-cancel, future-cancelled? and future?

14.7.2. promise and deliver delay and force

14.7.3. atom, swap!, reset! and compare-and-set! add-watch and remove-watch

14.7.4. agent, send, send-off, send-via, set-agent-send-executor! and set-agent-send-off-executor! restart-agent, shutdown-agents, release-pending-sends, await and await-for agent-error, set-error-handler!, error-handler, error-mode and set-error-mode!

14.7.5. pmap, pcalls and pvalues

14.8. Mutation and Side Effects

14.8.1. transient, persistent!, conj!, pop!, assoc!, dissoc! and disj!

14.8.2. doseq dorun doall do

14.8.3. volatile!, vreset!, vswap! and volatile?

14.9. Everything Else

14.9.1. bit-and, bit-or, bit-xor, bit-not, bit-flip, bit-set, bit-shift-right, bit-shift-left, bit-and-not, bit-clear, bit-test and unsigned-bit-shift-right

14.9.2. symbol, keyword and find-keyword

14.9.3. walk and zipper

What's inside

Each function or macro is presented with:

  • An introduction including areas of application and main goals
  • A more rigorous contract section, including parameters and return types
  • Real world examples of the function in action
  • Background and conceptual information necessary to better understand the function
  • Diagrams and comparison tables
  • Implementation details and performance implications

About the reader

For developers of all skill levels who need a thorough reference to Clojure standard library.

About the author

Renzo Borgatti is a software engineer with more than 15 years of experience in the field. Renzo worked with Java, Ruby, and Objective-C before discovering Clojure and functional programming a few years ago, a passion that quickly turned into professional work. He's a frequent speaker at user groups and conferences.


Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.

FREE domestic shipping on three or more pBooks