How is AnyPublisher being implemented here?

I’ve been reading through OpenCombine to get a better understanding of the types involved with Combine. In particular I was curious how AnyPublisher is implemented. While the implementation makes a lot if sense I’m a bit lost understanding what’s happening at It appears to be calling init on the concrete Publisher but I guess it’s somehow actually calling AnyPublisher.init? What am I missing?

return init(self) would be calling it on the concrete Publisher (except that this syntax isn’t legal for init specifically). return .init(self), with a dot, is calling it on the type implied by the context – which in this case is the return type, AnyPublisher<Output, Failure>.

This is the same syntax as when you refer to an enum case as .case instead of

1 Like

Wow that’s very interesting, definitely a big piece that was missing from my understanding of the type system, many thanks!

Terms of Service

Privacy Policy

Cookie Policy