Collections

So far, we have been working with symbols bound to a single variable, as in (def price 3.95). But what if you had a group of five prices that you wanted to work with, for example, discounting them all by 10% or finding their mean and standard deviation? You certainly don’t want to do something like this:

(def price1 3.95)
(def price2 6.80)
(def price3 2.49)
(def price4 5.33)
(def price5 1.99)

Imagine what would happen if you had twenty prices to keep track of. There must be a better way, and that better way is collections, which allow you to bind a single symbol to a collection of related data.

The main types of collections in Clojurescript are:

Next Section - Lists