May 2018
Beginner to intermediate
290 pages
6h 43m
English
You can get a huge amount of programming mileage out of sequences and the panoply of functions that Clojure provides to process them. For example, imagine that you were working on a sales application for your book business and, starting with the books vector we saw earlier, you needed to format a string proclaiming the three top-rated books, something like this:
| | "Emma // Dracula // Deep Six" |
Step one is to find the top three books, by rating. We could start by sorting the books by their rating:
| | (sort-by :rating books) |
That will give us the books from lowest to highest rating, but the other way around is more useful:
| | (reverse (sort-by :rating books)) |
Then we can then pull out the three highest-rated books, with take ...
Read now
Unlock full access