Description Usage Arguments Details Value Author(s) See Also Examples
UseFunction manages the dispatching for multipart functions in lambda.r. This is used internally by lambda.r.
1 2 | UseFunction(fn, fn.name, ...)
NewObject(type.fn, type.name, ...)
|
fn |
The function reference that is being applied |
fn.name |
The name of a function that uses functional dispatching. This is just the name of the function being defined |
type.fn |
The function representing the type constructor |
type.name |
The name of the type |
... |
The arguments that are passed to dispatched functions |
This function is used internally and generally does not need to be called by an end user.
Returns the value of the dispatched function
Brian Lee Yung Rowe
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # Note that these are trivial examples for pedagogical purposes. Due to their
# trivial nature, most of these examples can be implemented more concisely
# using built-in R features.
reciprocal(x) %::% numeric : numeric
reciprocal(x) %when% {
x != 0
} %as% {
1 / x
}
reciprocal(x) %::% character : numeric
reciprocal(x) %as% {
reciprocal(as.numeric(x))
}
seal(reciprocal)
print(reciprocal)
reciprocal(4)
reciprocal("4")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.