concept AnyIterator in category swift
appears as: AnyIterator

This is an excerpt from Manning's book Swift in Depth.
For Bag, you had very little work to do when extending Sequence. All you did was create an instance of BagIterator and return it. In a scenario like this, you can decide to return AnyIterator to save you from creating a BagIterator altogether.
AnyIterator is a type erased iterator, which you can think of as a generalized iterator. AnyIterator accepts a closure when initialized; this closure is called whenever next is called on the iterator. In other words, you can put the next functionality from BagIterator inside the closure you pass to AnyIterator.