apply()

Returns a list of the value of the expression in the second argument, evaluated with respect to each item in the first argument.

Synopsis

apply(list-expression, pair-expression)

Description

This function returns a list of values evaluated using a given expression. The first argument specifies the list of values to apply using the expression in the second argument.

In the expression to evaluate, the special variable “_” is a place-holder for the values applied from the given list-expression.

Parameters

list-expression

An expression that evaluates to a list of numeric values.

pair-expression

An expression which is applied using each numeric value from the list.

Returns

Returns a list of the same length as the given list-expression, where each entry in the list is formed by applying the corresponding value in the list to the given pair-expression.

Examples

The following example returns a list with values twice the size of the input list:

apply(distance_list, 2 * _)

For example:

distance_list = list(10, 20, 30, 50)
roundtrip_list = apply(distance_list, 2 * _)

After this example, roundtrip_list would hold the list (20, 40, 60, 100).

See Also

filter_values(), index_values(), index_agents(), intersection(), union(), select(), pair-expression