Chapter 22, Bronze Challenge Solution

Here’s my solution for the bronze Challenge.

extension Collection where Element == Exercise {
    func count(where test: (Element) -> Bool) -> Int {
        var count: Int = 0
        for exercise in self where test(exercise){
            count += 1
        }
        return count
    }
}

But does anyone know why Collection is the better protocol to add this extension to than Sequence?

Collection is a better choice because Sequence, by definition, is used to represent ordered collections. For example, an Array instance is a sequence but a Set instance is a collection.

Gotcha. Thanks for clearing that up for me!