Destructuring
    Demystified
    Demystified
A Tour of clojure’s Destructuring forms by
    someone hopelessly unqualified.
TIL Session #1
What is it?

Why use it?

Where should I use them?

When should I use them?

How?

Cool tricks
What?
“A method of positionally    binding locals based on
 an expected   form for a composite data structure”
                - The Joy of Clojure
                        OR

           “Picking out the bits you need”
                   - Tom Crinson
Why?

A lot of times you don’t need the whole
structure.

Keeps code readable

Keeps functions focussed
Why?
Where?


let form

function parameters
When?

“Whenever you find yourself calling nth
                                     repeatedly, or
looking up constants in a map or using first or next,
     ask yourself if restructuring would be a better fit.”
                     - The Joy of Clojure
Vectors - Remainder




       Slurp up remaining names
Vectors - :as




Keeps as a vector - untouched
Vectors - Associative
      Destructuring




Declare local names as indices into a vector
Maps



     ‘Tis a bit repetitive...

And... keywords on the right?
Maps - keywords
      :keys




      :strs




     :syms ...
Maps - default Values
Cool Tricks -1
Nested Destructuring
Cool Tricks - 2



Works on other data structures!
Fin

Destructuring demystified