Conditional conformance allows a generic type to conform to a protocol only if the type meets certain conditions. For example, if we wanted our List type to conform to the equitable protocol only if the type stored in the list also conformed to the equitable protocol, we could use the following code:
extension List: Equatable where T: Equatable { static func ==(l1:List, l2:List) -> Bool { if l1.items.count != l2.items.count { return false } for (e1, e2) in zip(l1.items, l2.items) { if e1 != e2 { return false } } return true } }
This code will add conformance to the Equitable protocol to any instance of the List type where the type that is stored in the list also conforms to the Equitable protocol.
There is a new function shown here that we...