RConsortium / S7

S7: a new OO system for R
https://rconsortium.github.io/S7
Other
399 stars 33 forks source link

Group generics #353

Open hadley opened 1 year ago

hadley commented 1 year ago

Related to #320, we need some way to register methods for group generics. I think the syntax should probably look something like this?

library(S7)
foo <- new_class("foo", class_integer)
method(Math, foo) <- function(x) {
   foo(Math(super(x, class_integer)))
}
method(Ops, list(foo, class_any)) <- function(x, y) {
   foo(Ops(super(x, class_integer), y))
}
method(Ops, list(class_any, foo)) <- function(x, y) {
   foo(Ops(x, super(y, class_integer)))
}