a!applyComponents() Function

Check out the new looping function, a!forEach(). It does everything a!applyComponents() does but with easier syntax, better null handling, and support for interface components.

Calls a rule or function for each item in a list and supports the preservation of the local state on interfaces.

Syntax

a!applyComponents( function, array, arrayVariable )

  • function (Rule or Function Reference): Rule or expression function.
  • array (Any Type Array): Array of elements that the function iterates through.
  • arrayVariable (Any Type Array): Optional variable for preserving component or rule data.

Returns

Any Type Array

Notes

Use fn!functionName to reference an expression function and rule!ruleName to reference a rule.

The arrayVariable parameter should be passed an uninitialized local variable created via a!localVariables() or load(). a!applyComponents will store an array of state tokens in that variable. This is only required if a!applyComponents() is being invoked as part of an interface and the order of elements in array is not stable. If items in array swap positions, if an item is added to the beginning or middle, and if an item is removed from the beginning or middle, the same transformation should be applied to the arrayVariable array.

See also: a!localVariables() and load()

If array will not change, or if additions and removals only occur at the end of the array, arrayVariable is not needed.

Passing a null array returns a null list without executing the function.

To use rules or functions that take more than one argument, use the merge() function. For example, given a rule g(x, y), a!applyComponents(function: rule!g, array: merge({a, b, c}, {d, e, f})) returns {g(a, d), g(b, e), g(c, f)}.

The result of each operation is appended to each other in the same order as their corresponding item in the input list. If the result of each operation is an array, a!applyComponents() returns a two-dimensional array which can then be used for further computation. When the two-dimensional array is saved into a process variable, a node input or a custom data type, the array is flattened to a one-dimensional array. Local variables, however, can store the two-dimensional array without flattening it.

See also: a!localVariables()

If you save the nested arrays into a process variable for multiple values, the nested function is flattened. Keep in mind that casting to a flattened array only happens when saving into a process variable, node input, custom data type, or custom data type field.

See also: Arrays in Expressions

to avoid having the nested function flatten, you can use the output of the apply() function as the input for a merge() function.

see also: merge()

Examples

You can copy and paste these examples into the Expression Rule Designer to see how this works.

Given an interface rule renderEmployeeDetails and an array of employees ri!employees:

1
2
3
4
5
6
7
8
	a!localVariables(
	  local!stateTokens,
	  a!applyComponents(
	    function: rule!renderEmployeeDetails,
	    array: 1 + enumerate(length(ri!employees)),
	    arrayVariable: local!stateTokens
	  )
	)

a!applyComponents(function: fn!isnull, array: {1,2,null,3,null,4}) returns false, false, true, false, true, false

For examples of full interfaces using a!applyComponents(), see Interface Recipes.

Open in Github Built: Thu, Feb 23, 2023 (02:59:22 PM)

On This Page

FEEDBACK