January 2017
Intermediate to advanced
565 pages
13h 46m
English
Destructuring is a feature in Clojure that is not common in other lisps; the idea is to allow you to write more concise code in scenarios where code doesn't really add value (for example, getting the first element from a list or the second parameter from a function) and concentrating only on what is important to you.
In order to understand this better, let's see an example of why destructuring can help you:
(let [v [1 2 3]] [(first v) (nth v 2)]) ;; [1 3]
What's wrong with the previous code? Nothing really, but you need to start thinking about what is v, what the first value of v is, what the nth function does, and at what index v starts.
Instead we can do this:
(let [[f s t] [1 2 3]] [f t]) ;; [1 3]
Once you are used to destructuring, ...
Read now
Unlock full access