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​
FN([arg1...], arg2)
Arguments | Description |
| Optional. Expected argument or set of arguments. However, a function can be defined that takes no external arguments. |
| 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 |
Let's say we're given a response with the following vehicle performance information.
{"data": {"vehicle_ratings": [92,84,71,80,96]}}
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 MAPMAP(FN(x, x + 4), data.vehicle_ratings)​# Returns [96, 88, 75, 84, 100]
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 argumentsMAP(FN(x, y, x + y), data.vehicle_safety_ratings, data.vehicle_performance_ratings)​# Returns [187, 165 ,148, 163, 186]