#65: Conditional Conformance in Swift

Conditional conformance lets a generic type gain behavior only when its generic arguments satisfy some constraints.

extension Array: Equatable where Element: Equatable {}

This reads naturally: arrays are equatable when their elements are equatable.

It is one of the features that makes Swift generics feel expressive without needing a large hierarchy of special-case types.


I'm also on Twitter and GitHub.

Subscribe via RSS.