WITH arguments occur in a closure, and as such can be defined as variables within the scope of the function arguments.


WITH([arg1...], arg2)

  • arg1 is a variable binding or set of bindings, in the form of tuples, wherein the first argument is the variable name and the second argument is the variable value

  • WITH takes an indeterminate number of variable binding arguments

  • arg2 is an expression that must always occur as the last argument - all previous argument pairs will constitute variable assignments. The result of this expression will be what is returned by the WITH function.


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 WITH:

WITH(addcurve, FN(x, x + 4), MAP(addcurve, data.vehicle_ratings))

This would return:

[96, 88, 75, 84, 100]

To abstract it even further, we could add a second variable representing the curve:

WITH(curve, 100 - MAX(data.vehicle_ratings), addcurve, FN(x, x + curve), MAP(addcurve, data.vehicle_ratings))

This would also return:

[96, 88, 75, 84, 100]