List Operations

A list is constructed by specifying a sequence of comma (,) separated values of the element type, surrounded by brackets ([]) . For instance, an example literal for List(Double) is [3.5, 6.7, 8.3] and an example for List(String) is ["HCL", "Detect"]. An empty list requires casting to define its type. As an example, an empty List(String) can be specified as List(String)([]).

An expression in HCL Detect Expression Language can contain a few basic list operations: containment (in), non-containment (not in), indexing ([i]), slicing ([i:j]), concatenation (+), and size inquiring (size()).

Containment yields a Boolean answer, identifying whether an element is contained within a list. For instance, 3in[2,5,3] yields true, whereas 8 in [2, 5, 3] yields false. Non-containment is the negated version of the containment. For instance, 3 not in [2, 5, 3] yields false, whereas 8 not in [2, 5, 3] yields true.

Indexing yields the element at the specified index within the list. 0-based indexing is used and indices are of type Int32. For instance, [2, 5, 3][1] yields 5, and [2, 5, 3][-3] yields 2. The index should be between -size and size-1, inclusive. An index that is out of these bounds will result in an evaluation error at runtime.

Slicing yields a sub-list. The start index is inclusive, whereas the end index is exclusive. If the range is out of bounds, then an empty list is returned. For instance, [2,5,3,7][1:2] yields [5], [2, 5, 3, 7][1:3] yields [5, 3], [2, 5, 3, 7][1:1] yields [], [2, 5, 3, 7][3:5] yields [7], [2, 3, 4][-2:-1] yields [3], [2, 3, 4][-5:-1] yields [2, 3], [2, 3, 4][1, 6] yields [3, 4], and [2, 5, 3, 7][4:6] yields [].

Concatenation results in a list that contains the elements from the first list followed by the elements from the second list. For instance, [1,2]+[3] yields [1, 2, 3].

The size of a list can be retrieved via the builtin function list.size().