FN

FN denotes an anonymous function. Similar to WITH, FN is a closure and allows variables to be defined within the argument context and then referenced later. It takes an indeterminate number of arguments.

Function category: Special

Syntax

FN([arg1...], arg2)

Arguments

Description

arg1

Optional. Expected argument or set of arguments. However, a function can be defined that takes no external arguments.

arg2

Required. Body of the function and must always occur as the last argument. The result of this expression will be what is returned by the FN function.

Examples

Let's say we're given a response with the following vehicle performance information.

{
"data": {
"vehicle_ratings": [
92,
84,
71,
80,
96
]
}
}

Example 1: Find relative vehicle scores

If we wanted relative vehicle scores with the highest existing score serving as a benchmark, use the following function.

# Pass the function FN in the function argument to MAP
MAP(FN(x, x + 4), data.vehicle_ratings)
# Returns [96, 88, 75, 84, 100]

Example 2: Using multiple arguments

We can also use multiple arguments, as in the following function.

{
"data": {
"vehicle_safety_ratings": [
92,
84,
71,
80,
96
],
"vehicle_performance_ratings": [
95,
81,
77,
83,
90
]
}
}

If we wanted to generate a combined_vehicle_rating, use the following function. FN with MAP can take two arguments and generate a combined_vehicle_rating:

# Pass the function FN in the function argument to MAP
# using multiple arguments
MAP(FN(x, y, x + y), data.vehicle_safety_ratings, data.vehicle_performance_ratings)
# Returns [187, 165 ,148, 163, 186]