May 2018
Beginner to intermediate
290 pages
6h 43m
English
Multi-arity and variadic functions are great for those situations where you want to build functions that are less picky about the number of arguments they will accept. Sometimes what you want is to be able to vary your function’s behavior based on some other aspect of the values that get passed to it.
For example, imagine that our system was getting book data from various sources, in different formats. Some books still look like the maps we’ve been using:
| | {:title "War and Peace" :author "Tolstoy"} |
While others come in maps with different keys:
| | {:book "Emma" :by "Austen"} |
And still others are encoded in vectors:
| | ["1984" "Orwell"] |
Clearly we could handle all of this by writing a function to convert the odd-ball formats ...
Read now
Unlock full access