Lambda
|
This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics. |
Lambda( params, expression )
lambda_( params, expression )
Lambda( params, expression )
Lambda( params, expression )
Lambda( params, expression )
Lambda( params, expression )
Description
The Lambda function is an anonymous function that performs lazy
execution of custom code. It allows you to organize and execute almost
any of the FQL statements.
A Lambda can take zero or more parameters. Lambdas that
accept multiple parameters must use a params array to represent all of
the parameters. In this case, the items inside the params array are
the arguments, not the array itself. The params array must have the
same number of items as the caller provides, or an error occurs.
When a caller of a Lambda includes multiple parameters, such as
when processing index entries with multiple values fields, your
function might not need every item in the params array. Instead of
creating a name for an unneeded parameter, you can use an _
(underscore) instead; it signals that the function should ignore that
parameter.
The Lambda parameters may be accessed inside the Lambda code
using the Var statement (except the _ parameter; it is not a
named variable, it is a placeholder for a variable that should be
ignored).
|
Two functions are considered equal if their syntax is identical. For example: |
Parameters
| Parameter | Type | Definition and Requirements |
|---|---|---|
|
Value or Array |
A single Value, or an array of zero or more Values. |
|
FQL expression |
An FQL expression to be evaluated. |
Examples
-
The following query uses the
Mapfunction to provide a single argument to theLambda. TheLambdatakes the parameter calledname, resolves it to the value "Hen ", and then provides it to the first parameter to concatenate with the string "Wen". The result of "Hen Wen" is then returned.[ 'Hen Wen' ][ "Hen Wen" ][Hen Wen]Arr(StringV(Hen Wen))["Hen Wen"][ 'Hen Wen' ] -
The following query passes multiple arguments to a
Lambda. The number of values in the array passed into theLambdaand the number of arguments in theLambdamust match exactly. In this example, theMappasses an array with two elements and theLambdatakes an array with two elements. TheLambdaresolves the two arguments to their values and then calls theConcatfunction with the values.[ 'Hen Wen' ][ "Hen Wen" ][Hen Wen]Arr(StringV(Hen Wen))["Hen Wen"][ 'Hen Wen' ] -
The following query passes more arguments to the
Lambdathan are declared. In this case, the_(underscore) has been provided to theparamsarray so that theLambdafunction knows to discard the extra arguments. If the_had not been provided, this function would have returned an error.[ 'Hen' ][ "Hen" ][Hen]Arr(StringV(Hen))["Hen"][ 'Hen' ] -
The following query uses the
Mapfunction to provide two objects to theLambdaas theuserparameter. TheLambdaselects theemailfield from each object, which becomes part of the response:[ 'henwen@black.cauldron', 'taran@black.cauldron' ]['henwen@black.cauldron', 'taran@black.cauldron'][henwen@black.cauldron taran@black.cauldron]Arr(StringV(henwen@black.cauldron), StringV(taran@black.cauldron))["henwen@black.cauldron", "taran@black.cauldron"][ 'henwen@black.cauldron', 'taran@black.cauldron' ]