concept bag in category swift

appears as: bag, bags, A bag
Swift in Depth

This is an excerpt from Manning's book Swift in Depth.

An iterator is like a bag of groceries— you can pull elements out of it, one by one. When the bag is empty, you’re out. The convention is that after an iterator depletes, it returns nil and any subsequent next() call is expected to return nil, too, as shown in this example.

A bag can store anything that’s Hashable. Even though a bag can store anything, it can’t simply mix and match types—such as strings and integers—just like with Array or Set.