-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Labels
area/logicrelated to logic/dynamics/expressionsrelated to logic/dynamics/expressionskind/feature-requestNew feature or requestNew feature or requestorg/ssbIssues relevant for Statistisk sentralbyrå.Issues relevant for Statistisk sentralbyrå.squad/dataIssues that belongs to the named squad.Issues that belongs to the named squad.status/for-considerationIssues that will be considered for future deliveriesIssues that will be considered for future deliveries
Description
Right now, the expression language does not work with lists/arrays or objects, and will simply return null if you try to look one up from the data model. This is unfortunate, and the language should support these values - but we need to provide tools to manipulate them as well.
Needed functionality:
-
listfunction- Right now, all expressions are JSON arrays. If we want to support lists/arrays in the expression language, we need a way to represent a static list of values. Say, for example, that you wanted to check if a data model path is in a list of values with
["in", ["dataModel", ...], ["value1", "value2", "value3"]], the expression engine would think["value1", "value2", "value3"]is another expression - and halt when the functionvalue1is not found. - So, to mitigate this problem, we could create a
listfunction that simply takes any amount of parameters and returns them as a list/array. So the above could be written as["in", ["dataModel", ...], ["list", "value1", "value2", "value3"]].
- Right now, all expressions are JSON arrays. If we want to support lists/arrays in the expression language, we need a way to represent a static list of values. Say, for example, that you wanted to check if a data model path is in a list of values with
-
listLengthfunction (or similar - decide in tandem with the string length function name in Expressions: New simple functions #1176)- An obvious function to include is one to measure the length of a list (given as the first argument).
- Lookup a
groupandlistbinding- A
groupbinding binds to a list/array of objects. If we support both data types in the expression language, we should support looking up these values using thecomponentfunction. I think the most obvious thing here is to extendcomponentto work on any binding type (if there is only one binding), and allow you to specify which binding (such asaddress) as a second parameter if the component has multiple bindings.
- A
-
objKeysfunction (or similar)- A function that returns a list of keys inside an object, simply
Object.keys()
- A function that returns a list of keys inside an object, simply
-
pluckfunction- This function should be the powerhouse of the object support. It should pluck a value from an object (given a key). If given a list as a parameter, it should pluck out the key from every object in the list and return a list.
- Example:
["pluck", "name", [{"name": "Ole Martin"}, {"name": "Per"}]]=>["Ole Martin", "Per"] - We should create robust tests for this so we don't end up supporting side-effects like looking up the length of a list of lists (because
list.lengthis valid in javascript)
-
atIndexfunction- This function is for lists what
pluckis for objects. It is named differently to indicate they are not interchangeable, but they operate the same. If you["atIndex", 1, ["list", 1, 2, 3]]you should get2back. - We should create robust tests for this so we don't end up supporting side-effects like picking characters from a string.
- This function is for lists what
-
firstfunction- First conceived in Dynamiske uttrykk: Mulighet til å vise tekst fra skjult felt #1669 (comment)
- Similar to
atIndex, but in cases where you don't know the index. This way you can use an expression to find the first element in a list that matches another expression. - If this uses the
valuefunction for sub-expressions, it would ruin cases where you would like to use both thevaluefrom the current context (such as inoptionFilter) and this sub-expression to evaluate each list item. For that reason we might want to use something else, such as anitemfunction that behaves much likevalue.
Other simple functions (moved from #1176):
-
sum- Should take any amount of numbers as input, and also lists of numbers. All these numbers should be summed, and the resulting number should be returned.
nulland non-numeric values should be considered to be0(i.e. no effect on the sum).
- Should take any amount of numbers as input, and also lists of numbers. All these numbers should be summed, and the resulting number should be returned.
-
average- Same as above, but should produce the average of all the numbers summed.
nulland non-numeric values should be considered entries when calculating the average, as we should make a filtering function for those cases where invalid values should not be considered instead.
- Same as above, but should produce the average of all the numbers summed.
-
in- Shortcut function similar to
equals, but compares the first argument against multiple others to check if the first argument matches either one of them. Should support lists of items as parameters, and should then check inside the lists as well.
- Shortcut function similar to
-
notIn- Synonym for
["not", ["in", ....]]
- Synonym for
Other functions we should consider:
map(seeargvin Expressions: Allow for re-use of expressions altinn-studio#16764)- As an example, you could
["map", ["upperCase", ["argv", 0]], ["list", "foo", "bar"]]to get["FOO", "BAR"] - This would require deeper expression engine support than what is implemented for functions right now, as this is similar to a closure/callback data type.
- As an example, you could
filterreducesort(for lists of strings/numbers)reverse(for lists of strings/numbers)concatsupport for joining lists?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area/logicrelated to logic/dynamics/expressionsrelated to logic/dynamics/expressionskind/feature-requestNew feature or requestNew feature or requestorg/ssbIssues relevant for Statistisk sentralbyrå.Issues relevant for Statistisk sentralbyrå.squad/dataIssues that belongs to the named squad.Issues that belongs to the named squad.status/for-considerationIssues that will be considered for future deliveriesIssues that will be considered for future deliveries
Type
Projects
Status
In Progress
Status
No status