Skip to content

Instantly share code, notes, and snippets.

@kopasetik
Last active February 8, 2016 21:43
Show Gist options
  • Save kopasetik/711aff21db98605b1cde to your computer and use it in GitHub Desktop.
Save kopasetik/711aff21db98605b1cde to your computer and use it in GitHub Desktop.
Clojure function destructuring
; function destructuring
(defn eat-pizza-picky-style
; for eating only the good stuff from a pizza
[{:keys [dough meat sauce]}]
(println (str
"For this pizza, Whiskers only eats the "
dough ", " meat ", and " sauce
". It picks everything else off!")))
(def pepperoni-pizza {
:cheese "mozzarella"
:dough "white flour dough"
:meat "pepperoni"
:sauce "canned tomato sauce"
:veggies "peppers"
})
(def healthier-pizza {
:dough "whole grain dough"
:meat "chicken"
:sauce "alfredo sauce"
:veggies "peppers"
:cheese "swiss"
})
(def northwest-pizza {
:dough "sourdough"
:meat "salmon"
:sauce "dijon mustard"
:veggies "peppers"
:seasoning "dill"
})
(eat-pizza-picky-style pepperoni-pizza)
;=> For this pizza, Whiskers only eats the white flour dough,
;=> canned tomato sauce, and pepperoni. It picks everything else off!
(eat-pizza-picky-style healthier-pizza)
;=> For this pizza, Whiskers only eats the whole grain dough,
;=> alfredo sauce, and chicken. It picks everything else off!
(eat-pizza-picky-style northwest-pizza)
;=> For this pizza, Whiskers only eats the sourdough, dijon mustard,
;=> and salmon. It picks everything else off!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment