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([var1, ..., varN,] expr)
Arguments
Description
var1
Optional. Name for the first argument for the defined function. This name can be used in expr to refer to the first argument. If your function requires no arguments, only specify the expr.
varN
Optional. Name for the Nth argument.
expr
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.
1
{
2
"data": {
3
"vehicle_safety_ratings": [92, 84, 71, 80, 96],
4
"vehicle_performance_ratings": [95, 81, 77, 83, 90]
5
}
6
}
Copied!

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.
1
# Pass the function FN in the function argument to MAP
2
MAP(
3
FN(x, x + 4),
4
data.vehicle_safety_ratings
5
)
6
7
# Returns [96, 88, 75, 84, 100]
Copied!

Example 2: Using multiple arguments

We can also use multiple arguments, as in the following function. 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:
1
# Pass the function FN in the function argument to MAP
2
# using multiple arguments
3
MAP(
4
FN(x, y, x + y),
5
data.vehicle_safety_ratings,
6
data.vehicle_performance_ratings
7
)
8
9
# Returns [187, 165 ,148, 163, 186]
Copied!
Last modified 7mo ago
Export as PDF
Copy link