Replies: 7 comments
-
Syntax for lambda/closure is not supported but there is a workaround as one discussion thread shows: #436 it should be able to do what you want. |
Beta Was this translation helpful? Give feedback.
-
What about creating a LAMBDA function (similar to MS Excel)? |
Beta Was this translation helpful? Give feedback.
-
@oswaldobapvicjr How would we know that the LAMBDA function first parameter has to be set to the actual array value? |
Beta Was this translation helpful? Give feedback.
-
Maybe it's not so easy (or even possible). But one first idea would be to accept the The The idea is to have the |
Beta Was this translation helpful? Give feedback.
-
@oswaldobapvicjr then what's the difference between using I didn't propose to add this as a new function to the repository because after running through the array, the variable list will have some kind of 'stray' value. In the case of |
Beta Was this translation helpful? Give feedback.
-
In order to implement those high-order functions without leaving any 'stray' variables after evaluation (in my opinion, 'stray' variables are not only inconvenience but could potentially overwrite other variables if users are not careful), I think we can consider using a temporary map / dataAccessor when the function is iterating through the array performing evaluations one by one. A modified map function may look like follows (I use map as an example but filter is essentially the same): @FunctionParameter(name = "array")
@FunctionParameter(name = "placeholder", isLazy = true)
@FunctionParameter(name = "mapper", isLazy = true)
public class MapFunction extends AbstractFunction {
@Override
public EvaluationValue evaluate(
Expression expression, Token functionToken, EvaluationValue... parameterValues)
throws EvaluationException {
List<EvaluationValue> array = parameterValues[0].getArrayValue();
String placeHolder = parameterValues[1].getExpressionNode().getToken().getValue();
ASTNode mapper = parameterValues[2].getExpressionNode();
List<EvaluationValue> mapped = new ArrayList<>();
DataAccessorIfc tmp = expression.getConfiguration().getDataAccessorSupplier().get(); // get a tmp dataAccessor
for (EvaluationValue value : array) {
tmp.setValue(placeHolder, value);
mapped.add(expression.evaluateSubtree(mapper, tmp));
}
return EvaluationValue.arrayValue(mapped);
}
} Here we need to add a new method for Expression:
There are some other concerns though:
|
Beta Was this translation helpful? Give feedback.
-
I moved this issue to the discussion board. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Something like the following write-up,
ARRAYFIND(data_mapping_model, item => item.map_type == '3')
loop through the array, then filter by the conditional expression to find every element that returns true。
Beta Was this translation helpful? Give feedback.
All reactions