Skip to content
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

Consider example of multiple dispatch with intersect(x, y) #419

Open
DavisVaughan opened this issue Aug 7, 2024 · 0 comments
Open

Consider example of multiple dispatch with intersect(x, y) #419

DavisVaughan opened this issue Aug 7, 2024 · 0 comments

Comments

@DavisVaughan
Copy link
Collaborator

Could be added to this section
https://rconsortium.github.io/S7/articles/generics-methods.html#multiple-dispatch

See also this thread
https://fosstodon.org/@jonocarroll/112913640978442903

intersect(x, y) is not a generic function in base R. We introduced the {generics} R package to turn it into a generic, so we could write methods on them in classes throughout the tidyverse - but the generic only dispatches on x and then it is up to the method to ensure that y is the right class.

It might be interesting to implement intersect(x, y) using multiple dispatch as a motivating example for that feature. I imagine that 99.99% of the time, you will end up only implementing a method for the case where x and y are the same type, i.e. for when they are both Date. But being able to express this in the type system rather than having the method confirm that y is the right type seems nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant