Destructuring demystified

432 views

Published on

A quick talk given at our workplace lunch learning sessions on the different ways to destructure composite data structures in Clojure.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
432
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Destructuring demystified

  1. 1. Destructuring Demystified DemystifiedA Tour of clojure’s Destructuring forms by someone hopelessly unqualified.
  2. 2. TIL Session #1What is it?Why use it?Where should I use them?When should I use them?How?Cool tricks
  3. 3. 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
  4. 4. Why?A lot of times you don’t need the wholestructure.Keeps code readableKeeps functions focussed
  5. 5. Why?
  6. 6. Where?let formfunction parameters
  7. 7. When?“Whenever you find yourself calling nth repeatedly, orlooking up constants in a map or using first or next, ask yourself if restructuring would be a better fit.” - The Joy of Clojure
  8. 8. Vectors - Remainder Slurp up remaining names
  9. 9. Vectors - :asKeeps as a vector - untouched
  10. 10. Vectors - Associative DestructuringDeclare local names as indices into a vector
  11. 11. Maps ‘Tis a bit repetitive...And... keywords on the right?
  12. 12. Maps - keywords :keys :strs :syms ...
  13. 13. Maps - default Values
  14. 14. Cool Tricks -1Nested Destructuring
  15. 15. Cool Tricks - 2Works on other data structures!
  16. 16. Fin

×