Lists
There are several ways to construct a list. The simplest way is by writing a list literal, a comma-separated sequence of
expressions within brackets.
For example, you can write [10, 20, 30] or ["a", "b", "c"]. Note that any type of value can be placed inside a list.
For example, you could have a list of lists, such as [[10, 20], [30, 40]].
The second way to construct a list is via foreach … select … expressions, also known as comprehensions. Comprehensions
are described in details below.
The third way to construct a list is to append two lists together.
For example, if list1 and list2 are two lists of items of the same type, then list1 + list2 is the list consisting
of all items from list1 and list2 (preserving order, with list1 items first).
The fourth way to construct a list is to take the difference of two lists.
For example, if list1 and list2 are two lists of items of the same type, then list1 - list2 is the list consisting
of all items from list1 that are not in list2 (preserving order).
Additionally, a list of numbers in a range can be constructed with fromTo(a, b), which equals the list of numbers
starting from a and ending with b.
For example,fromTo(1, 3) is the same as [1, 2, 3]. If the second argument is smaller than the first, as
in fromTo(3, 1), the returned value is the empty list.
Besides the above, the following operations are available on lists.
length(list): the length of a list. For example,length(["a", "b"])is2.item in list: returnstrueif and only if the element represented by expressionitemis a member of the list represented by the expressionlist. For example,"b" in ["a", "b"]returns true.item not in list: returnstrueif and only if the element represented by expressionitemis not a member of the list represented by the expressionlist.distinct(list): returns the unique items inlist. In other words,distinctdeduplicates the list while preserving the order of the items in the original list.max(list): returns the greatest item in thelist, ornullif there are no items in the list. The greatest item in a collection is selected with the same order used for comparing items with relational expressions such as less-than (<) and greater-than (>). See Section comparisons for more detail on the order of values.min(list): returns the least item in thelist, ornullif there are no items in the list. The least item in a collection is selected with the same order used for comparing items with relational expressions such as less-than (<) and greater-than (>). See Section comparisons for more detail on the order of values.maxBy(list, attributeGetter): returns the greatest item in thelist, where items are ordered by the value returned by applyingattributeGetterto the item. For example, if the following function has been declaredgetRoutePrefix(route) = route.prefix; // Gets the prefix of a IpEntry route, and ifroutesis a variable referring to some list ofIpEntryrecords, thenmaxBy(routes, getRoutePrefix)evaluates to the route with the largest prefix (aka subnet) (see Section comparisons for more on how subnets are ordered). Similar tomaxandmin, this function returnsnullif there are no items in the list. Note that the second argument tomaxBy, calledattributeGetterabove, must be a function declared within the NQE check.minBy(list, attributeGetter): returns the least item in thelist, where items are ordered by the value returned by applyingattributeGetterto the item. For example, if the following function has been declaredgetRoutePrefix(route) = route.prefix; // Gets the prefix of a IpEntry route, and ifroutesis a variable referring to some list ofIpEntryrecords, thenminBy(routes, getRoutePrefix)evaluates to the route with the smallest prefix (aka subnet) (see Section comparisons for more on how subnets are ordered). Similar tomaxandmin, this function returnsnullif there are no items in the list. Note that the second argument tominBy, calledattributeGetterabove, must be a function declared within the NQE check.sum(list): The sum of a list of numbers. For example,sum([1, 2, 3])equals6.join(delimiter, list): the result of concatenating together the elements inlistof typestringusingdelimiterbetween each element. For example,join("", ["a", "b"])evaluates to"ab",join(" ", ["a", "b"])evaluates to"a b", andjoin(", ", ["a", "b"])evaluates to"a, b",