Skip to contents

Called from the body of an impl, r8next_impl() calls the impl that the running one takes precedence over: that of the nearest ancestor, after the type that provides the running impl, with an impl of the trait, or else the trait's default implementation. For a method that dispatches on several arguments, the next impl is the most specific applicable impl less specific than the running one; when two are, each more specific in one position, r8next_impl(Type, ...) names the one to continue to. It passes the current values of the running impl's formals, so an impl may change its arguments first, as with NextMethod(); generics in the next impl dispatch on the values passed. Every impl that R8 registers continues this way, an S3 method declared with implement() or impl() included.

Usage

r8next_impl(...)

Arguments

...

Optional R8 type objects: the impl to continue to, one per dispatched argument, by position or by name, as implement() takes them; it applies to the current arguments.

Value

The value of the next impl. Without a next impl, with two next impls, and for a first argument whose type is not the provider of the running impl or one of its descendants, raises r8_dispatch_error.

Examples

op <- options(r8.namespace = "demo")
Range <- new_struct("Range", fields = list(lo = type_double(), hi = type_double()))
Window <- new_struct("Window", fields = list(label = type_character()), extends = Range)
span_text <- generic("span_text", params(x))
implement(span_text, Range) <- function(x) paste(x$lo, "to", x$hi)
implement(span_text, Window) <- function(x) paste(x$label, r8next_impl())
span_text(Window(lo = 1, hi = 2, label = "w"))
#> [1] "w 1 to 2"
options(op)