Last active
February 8, 2016 21:43
-
-
Save kopasetik/711aff21db98605b1cde to your computer and use it in GitHub Desktop.
Clojure function destructuring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; 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