apply()

Synopsis

Runs the given function with the supplied args. The last argument must be a list , and the elements of the list are supplied to the function individually. The directly supplied arguments (after function) are typically used for any required arguments to function, while the final list argument is a convenient way to supply optional arguments... but all the arguments can be supplied in one list if preferred (see examples below). This function is commonly used when you have code that must decide at run-time which of several functions to run.

Syntax

apply ( function As Name, _
        args... As Any ) As Any 
Argument Type Description
function Name the name of the function to apply
args Any arguments for the function being applied (last argument must be a list).

Example 1

Intent >apply(:min, {3.0, 4.5, 1.5, 7.3}) 
--> 1.5 
This example applies the min() function to a number of arguments. These can be supplied either as a single argument (a list of values), or as separate arguments (as long as last argument is a list ). The next two examples produce the same result.

Example 2

Intent >apply(:min, 3.0, 4.5, {1.5, 7.3}) 
--> 1.5 

Example 3

Intent >apply(:min, 3.0, 4.5, 1.5, 7.3, {}) 
--> 1.5 

Example 4

Intent >apply(:myFunc, {2, 3}) 
--> True 
In this example, the following custom function myFunc() was applied to the list of two numbers.
Function myFunc(Number x, Number y) As Boolean 
    myFunc = x < y 
End Function