Is there any advantage in using AnyPublisher with Swift 5.7?

Unfortunately, it’s not possible to do this in the general case. The classic example is Equatable. Equatable.== is only defined on Self; it is meaningless to ask whether two unrelated types are equal. But if the singular any Equatable type itself conformed to Equatable, you could do something like (42 as any Equatable) == ("Hello" as any Equatable), and the compiler would not be able to synthesize a meaningful implementation of (any Equatable).==.

2 Likes