Destructuring Function Arguments
Not only does destructuring work with all the sequential types (and, as we’ll see in a minute, with maps), but it’s also not limited to let. Most notably, you can use destructuring to drill into the arguments passed to a function. Using destructuring with your function arguments is nearly identical to using it in a let, except that you don’t supply the value—that comes from the call to the function. Here, for example, is a function that’s looking for a two-element vector:
| (defn artist-description [[novelist poet]] |
| (str "The novelist is " novelist " and the poet is " poet)) |
As I say, the value to be destructured is supplied when you call the function, so that this:
| (artist-description [:austen :dickinson]) ... |
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.