Setλ︎
A Clojure set is a persistent data structure that holds a unique set of elements. Again the elements can be of any type, however each element must be unique for a valid set.
Note Explore creating sets from existing collections. Notice what happens if you have duplicate values in the collection. Define sets directly using the
#{}
notation and see what happens if there are duplicate values.
Unique but not orderedλ︎
A set is not ordered by the values it contains. If you need a sorted set then you can use the sorted-set
function when creating a new set. Or you can run
Looking up values in a setλ︎
Sets can also use the contains?
function to see if a value exists in a set