Learn R Programming

lambda.r (version 1.1.0-3)

UseFunction: Primary dispatcher for functional programming

Description

UseFunction manages the dispatching for multipart functions in lambda.r. This is used internally by lambda.r.

Usage

UseFunction(fn.name, ...)
NewObject(type.name, ...)

Arguments

fn.name
The name of a function that uses functional dispatching. This is just the name of the function being defined
type.name
The name of the type
...
The arguments that are passed to dispatched functions

Value

  • Returns the value of the dispatched function

Details

This function is used internally and generally does not need to be called by an end user.

See Also

%as%

Examples

Run this code
# 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")

Run the code above in your browser using DataLab