Sequence operations

Concatenation

You can concatenate sequences in the same way as strings, with +. For example:

<#list ["Joe", "Fred"] + ["Julia", "Kate"] as user>
- ${user}
</#list>  

produces this output:

- Joe
- Fred
- Julia
- Kate

NOTE: Do not use sequence concatenation for many repeated concatenations, such as for appending items to a sequence inside a loop. Use it for things such as <#list users + admins as person>. Although concatenating sequences is fast and its speed is independent of the size of the concatenated sequences, the resulting sequence will always be a little slower to read then the original two sequences. This means that the result of many repeated concatenations is a sequence that is slow to read.

Sequence slice

With [firstindex..lastindex] you can get a slice of a sequence, where firstindex and lastindex are expressions that evaluate to number. For example, if seq stores the sequence "a", "b", "c", "d", "e", "f" then the expression seq[1..4] will evaluate to a sequence that contains "b", "c", "d", "e" (since the item at index 1 is "b", and the item at index 4 is "e").

The lastindex can be omitted, in which case it defaults to the index of the last item of the sequence. For example, if seq stores the sequence "a", "b", "c", "d", "e", "f" again, then seq[3..] will evaluate to a sequence that contains "d", "e", "f".

An attempt to access a sub-variable past the last sub-variable or before the first sub-variable of the sequence will cause an error and terminate template processing.

Next steps

String operations

Hash operations