You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 onx
and then it is up to the method to ensure thaty
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 wherex
andy
are the same type, i.e. for when they are bothDate
. But being able to express this in the type system rather than having the method confirm thaty
is the right type seems nice.The text was updated successfully, but these errors were encountered: