SRL Collection Functions

Immutable functions for inspecting, transforming, aggregating, and grouping lists and configuration collections.

any()

Definition and usage

Tests whether at least one candidate matches a scalar value or occurs in a collection.

Syntax

any(valueOrList, ...values)

Parameter values

ParameterAllowed typeRequiredDescription
valueOrList mixed Yes Scalar value or collection to search.
values mixed Yes One or more candidate values.

Return value

Return typeboolean
Outputtrue when any candidate is present.

Examples

Example 1
any(this.service, "HTTP", "TELNET")
Expected return value: true when either service is present
Example 2
any(appliance.interfaces.$name.network_type, "internet", "external")
Expected return value: true for a matching interface, uniform zone, or mixed zone
Example 3
any(split("a,b", ","), "x", "y")
Expected return value: false

all()

Definition and usage

Tests whether every candidate occurs in a collection.

Syntax

all(list, ...values)

Parameter values

ParameterAllowed typeRequiredDescription
list collection Yes Collection to search.
values mixed Yes One or more required values.

Return value

Return typeboolean
Outputtrue only when every candidate is present.

Examples

Example 1
all(this.service, "HTTP", "HTTPS")
Expected return value: true when both services are present
Example 2
all(split("a,b", ","), "a", "c")
Expected return value: false

array_keys()

Definition and usage

Returns the visible keys of a list or named configuration collection.

Syntax

array_keys(collection)

Parameter values

ParameterAllowed typeRequiredDescription
collection array Yes Source collection.

Return value

Return typelist
OutputSequential list of keys; private SRL annotation keys are omitted.

Examples

Example 1
array_keys(config.firewall.address)
Expected return value: ["all", "LAN", "DMZ"]
Example 2
array_keys(split("a,b", ","))
Expected return value: [0, 1]
Behavior: This is the safest way to obtain configuration object names without losing the original collection.

array_values()

Definition and usage

Returns visible collection values with sequential indexes.

Syntax

array_values(collection)

Parameter values

ParameterAllowed typeRequiredDescription
collection array Yes Source collection.

Return value

Return typelist
OutputA new sequential list; annotated configuration objects retain their metadata.

Examples

Example 1
array_values(config.firewall.address)
Expected return value: List of address objects
Example 2
array_values(split("a,b", ","))
Expected return value: ["a", "b"]

array_column()

Definition and usage

Extracts a field from every collection item that contains it.

Syntax

array_column(collection, field)

Parameter values

ParameterAllowed typeRequiredDescription
collection array Yes Collection of object-like entries.
field string Yes Field name or dot-separated nested field path.

Return value

Return typelist
OutputExtracted field values in source order; entries missing the field are skipped.

Examples

Example 1
array_column(config.firewall.address, "type")
Expected return value: List of address types
Example 2
array_column(config.firewall.policy, "name")
Expected return value: List of configured policy names

array_unique()

Definition and usage

Removes duplicate values while retaining the first occurrence.

Syntax

array_unique(collection)

Parameter values

ParameterAllowed typeRequiredDescription
collection array Yes Source values.

Return value

Return typelist
OutputNew sequential list of unique values.

Examples

Example 1
array_unique(split("B,a,b,A", ","))
Expected return value: ["B", "a"]
Example 2
array_unique(this.service)
Expected return value: First occurrence of each service
Behavior: Equality follows SRL conventions: strings are case-insensitive, numbers compare numerically, and object/list values compare by visible content.

array_sort()

Definition and usage

Natural-sorts a copy of a collection.

Syntax

array_sort(collection, direction = "asc")

Parameter values

ParameterAllowed typeRequiredDescription
collection array Yes Source values.
direction string No asc (default) or desc.

Return value

Return typelist
OutputNew sorted sequential list.

Examples

Example 1
array_sort(split("port10,port2,port1", ","))
Expected return value: ["port1", "port2", "port10"]
Example 2
array_sort(split("2,10,1", ","), "desc")
Expected return value: ["10", "2", "1"]
Behavior: Unlike PHP sort(), this function never mutates its input.

array_reverse()

Definition and usage

Returns collection values in reverse order.

Syntax

array_reverse(collection)

Parameter values

ParameterAllowed typeRequiredDescription
collection array Yes Source collection.

Return value

Return typelist
OutputNew reversed sequential list.

Examples

Example 1
array_reverse(split("a,b,c", ","))
Expected return value: ["c", "b", "a"]
Example 2
array_reverse(array_keys(config.firewall.policy))
Expected return value: Policy IDs in reverse configuration order

array_slice()

Definition and usage

Returns a sequential portion of a collection.

Syntax

array_slice(collection, offset, length = omitted)

Parameter values

ParameterAllowed typeRequiredDescription
collection array Yes Source collection.
offset number Yes Starting index; negative values count from the end.
length number No Maximum values returned; omit for the remainder.

Return value

Return typelist
OutputNew sliced sequential list.

Examples

Example 1
array_slice(split("a,b,c,d", ","), 1, 2)
Expected return value: ["b", "c"]
Example 2
array_slice(split("a,b,c", ","), -1)
Expected return value: ["c"]

array_sum()

Definition and usage

Adds the numeric value of every visible collection item.

Syntax

array_sum(collection)

Parameter values

ParameterAllowed typeRequiredDescription
collection array Yes Numeric or numeric-text values.

Return value

Return typenumber
OutputNumeric total; non-numeric values contribute zero.

Examples

Example 1
array_sum(split("1,2.5,3", ","))
Expected return value: 6.5
Example 2
array_sum(array_column(config.example, "score"))
Expected return value: Total configured score

array_group_by()

Definition and usage

Groups object-like entries by one or more fields in a single pass.

Syntax

array_group_by(collection, fields)

Parameter values

ParameterAllowed typeRequiredDescription
collection array Yes Named or sequential object collection.
fields string or list Yes One field path or a list of field paths, commonly created with split().

Return value

Return typelist of group objects
OutputEach group contains key, count, primary, members, and names fields. Group and member order follow the source collection.

Examples

Example 1
array_group_by(config.firewall.service.custom, split("protocol,tcp-portrange,udp-portrange", ","))
Expected return value: Groups services with the same selected fields
Example 2
array_group_by(config.firewall.address, split("type,subnet,fqdn", ","))
Expected return value: Groups addresses by type and selected values
Behavior: Use $group.count, $group.primary, $group.members, $group.names, and $group.key. String field values group case-insensitively. Original objects remain annotated, so name($group.primary), path($member), and finding subjects continue to work.