inject: Injects the callback function

Description Usage Arguments Value Examples

Description

Injects the callback function

Usage

1
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

1
2
3
4
5
6
7
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 ()))

dfci-cccb/injectoR documentation built on May 15, 2019, 5:12 a.m.