In the Wild

Examples of destructuring are easy to find if you look around in the Clojure ecosystem. For example, Korma,[21] the database library, contains this function, which helps set up connections to MySQL databases:

 (​defn​ mysql
 "Create a database specification for a
  mysql database. Opts should include
  keys for :db, :user, and :password.
  You can also optionally set host and port.
  Delimiters are automatically set to \"`\"."
  [{:keys [host port db make-pool?]
  :or {host ​"localhost"​, port 3306, db ​""​, make-pool? true}
  :as opts}]
 
 ;; Do something with host, port, db, make-pool? and opts
 )

Again we have the typical function with a docstring setup, but this function is using some interesting destructuring to ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.