Learn R Programming

injectoR (version 0.2.4)

inject: Injects the callback function

Description

Injects the callback function

Usage

inject(callback, binder = .binder)

Arguments

callback
function to inject, a function accepting arguments to be matched to injectable keys; no errors are thrown if no binding is found for a key, this is the intended mechanic for optional injection, if the callback is able to deal with a missing argument the argument becomes optional
binder
containing the injectables, defaults to root binder if omitted

Value

result of the injected callback evaluation

Examples

Run this code
inject (function (two) two, define (two = function () 2, binder = binder ()))
inject (function (power) power (2, 4), 
        define (power = function (power) function (x, n) if (n < 1) 1 else x * power (x, n - 1)))
inject (function (fibonacci) fibonacci (8),
        define (fibonacci = function (fibonacci)
          function (n) if (n < 3) 1
                       else fibonacci (n - 1) + fibonacci (n - 2), binder = binder ()))

Run the code above in your browser using DataLab