Clojure is based on collections, but how are they used? What are some patterns for making the most of them? This course introduces you to the workhorses of the Clojure programming language, the immutable collections.
Screencasts, Whiteboards, and Slides produced to help you learn
In Clojure, the common advice is “just use a map”. There’s some truth to that, but it’s obviously more complicated. Clojure gives you lots of ways to model a problem. In this course, I give you a peek behind the curtain. I work step-by-step through different iterations of a domain model, discussing what I’m thinking, why I’m trying something else. We model the game of solitaire, a card game we’re all familiar with.
Clojure sequences are lazy by default. That gives you big benefits like separation of concerns, but it also brings with it some gotchas. This course is mostly about exploring those gotchas–problems that can bite you if you’re not ready for them–and techniques to work with each one. Being prepared is the best antidote to a bad bite. After dealing with the downsides, we explore the big benefits.
Pragmatic and in-depth guides to a topic.
Clojure’s collections are central to Clojure programming. While in most languages, you might find collections somewhere in the standard library, in Clojure, they are front and center.
Parts of courses on specific topics
What do I mean by access patterns? It’s the underlying commonality between the collections. It answers the question: How will we access our information?
We look at another common access pattern, which is to associate a key and a value into a collection. The two collections that this works with are HashMap and Vector. Combined with Lookup value by key, we can do a convenient update operation.
When I first was learning Clojure, something was confusing: some operations, like map, took the collection as the last argument, and some, like conj, took the collection as the first argument. It was frustrating. But then I learned that they are in two different categories of functions. Learning that fact helped me be more productive in the language.
We can quickly check if an item is contained in a set. We can also check quickly if a key is in a Map, or if an index will work for a Vector.
A common access pattern that we often don’t think about is to count the elements. We don’t think about it because all of the collections implement it. But there is one big gotcha you should know about.
Sometimes we want to remove a key/value pair from a HashMap. We use the dissoc operator to do that.