Skip to content

Instantly share code, notes, and snippets.

@jessitron
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessitron/11201765 to your computer and use it in GitHub Desktop.
Save jessitron/11201765 to your computer and use it in GitHub Desktop.
The threading macro lets us define functions ABOUT data instead of making methods on classes, while still using a top-down ordering of code.
(defn addCustomer [sale, cust] (assoc sale :customer cust))
(defn addItems [sale, items] (assoc sale :items items))
(defn complete [sale, num] (println "Sale" num ": selling" (:items sale) "to" (:customer sale)))
(def sale { :store "Downtown" })
(-> sale
(addCustomer "Fred")
(addItems ["carrot", "eggs"])
(complete 100)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment