May 2018
Beginner to intermediate
290 pages
6h 43m
English
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]) ... |
Read now
Unlock full access