I don't understand why this doesn't compile. It does if I remove the where restriction from the P type.
import Combine
protocol Foo {
associatedtype P: Publisher where P.Output == Int
var publisher: P { get }
}
struct Bar: Foo {
var publisher: some Publisher {
Just(1)
}
}
The error says that Type 'Bar' does not conform to protocol 'Foo'. I guess it's because publisher return type is not just any some Publisher. But in SwiftUI, the View uses a similar approach, just that it doesn't have restrictions over the View type.
Is there any way I can make this code to compile?