-
Notifications
You must be signed in to change notification settings - Fork 7
FN denotes an anonymous function. FN, like WITH, is a closure, and as such allows variables to be defined within the argument context and subsequently referenced.
FN([arg1...], arg2)
-
arg1is the expected argument or set of arguments -
FNtakes an indeterminate number of arguments -
arg1is not required - a function can be defined that takes no external arguments -
arg2is the body of the function, and must always occur as the last argument. The result of this expression will be what is returned by theFNfunction.arg2is required.
Let's say we're given a response with some vehicle performance information that looks like this:
{
"data": {
"vehicle_ratings": [92, 84, 71, 80, 96]
}
}If we wanted relative vehicle scores, with the highest existing score serving as a benchmark, we could use FN = to describe that and apply it passing it as the function argument to MAP:
MAP(FN(x, x + 4), data.vehicle_ratings)
This would return:
[96, 88, 75, 84, 100]FN can also take multiple arguments. Given the following data:
{
"data": {
"vehicle_safety_ratings": [92, 84, 71, 80, 96],
"vehicle_performance_ratings": [95, 81, 77, 83, 90]
}
}We could use FN with MAP, which can take two arguments, and generate a combined_vehicle_rating:
MAP(FN(x, y, x + y), data.vehicle_safety_ratings, data.vehicle_performance_ratings)
This will return:
[187, 165 ,148, 163, 186]