Destructuring demystified

download Destructuring demystified

of 16

  • date post

    19-May-2015
  • Category

    Technology

  • view

    204
  • download

    0

Embed Size (px)

description

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

Transcript of Destructuring demystified

  • 1. DestructuringDemystifiedDemystifiedA Tour of clojures Destructuring forms bysomeone hopelessly unqualified.

2. TIL Session #1What is it?Why use it?Where should I use them?When should I use them?How?Cool tricks 3. What?A method of positionallybinding locals based on an expected form for a composite data structure- The Joy of ClojureOR Picking out the bits you need - Tom Crinson 4. Why?A lot of times you dont need the wholestructure.Keeps code readableKeeps functions focussed 5. Why? 6. Where?let formfunction parameters 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. Vectors - Remainder Slurp up remaining names 9. Vectors - :asKeeps as a vector - untouched 10. Vectors - AssociativeDestructuringDeclare local names as indices into a vector 11. Maps Tis a bit repetitive...And... keywords on the right? 12. Maps - keywords:keys:strs :syms ... 13. Maps - default Values 14. Cool Tricks -1Nested Destructuring 15. Cool Tricks - 2Works on other data structures! 16. Fin