New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Why would the AnyPublisher be used everywhere? #32
Comments
Hey @zrfrank Publishers in Combine maintain type information as you chain them. In the following example, the let publisher = Just<Int>(10)
.delay(for: .seconds(1), scheduler: RunLoop.main)
.debounce(for: .seconds(1), scheduler: RunLoop.main) So if we need to return this value from a function, we'd have to specify the full type information as the return type of the function. This would be crazy inconvenient and would lead to tight coupling between the function implementation and the consumers of this function: every time you change this chain of operators (even by swapping Just the same problem exists for SwiftUI views: the resulting view type might be insanely long for exposing this as the return type. That's why in Swift 5 there is We could have used
I hope my explanation makes sense - let me know if any clarification is needed. |
Thanks! Really excellent explanations! |
No description provided.
The text was updated successfully, but these errors were encountered: