collections.Seq
Returns a slice of integers starting from 1 or a given value, incrementing by 1 or a given value, and ending at a given value.
- Syntax
- collections.Seq LAST
- collections.Seq FIRST LAST
- collections.Seq FIRST INCREMENT LAST
- Returns
- []int
- Alias
- seq
Usage
The collections.Seq function returns a slice of integers starting from 1 or a given value, incrementing by 1 or a given value, and ending at a given value. The returned slice is limited to one million elements. Otherwise, the function returns an error.
Arguments
FIRST- (
int) The first integer in the sequence. Default is1ifLASTis positive, or-1ifLASTis negative. INCREMENT- (
int) The amount to add to each integer to get the next integer. Default is1ifLASTis greater than or equal toFIRST, otherwise-1. The function returns an error ifINCREMENTis zero, or if it moves the sequence away fromLAST. LAST- (
int) The integer at which to end the sequence. The sequence includesLASTif the increments reach it exactly. If you specify onlyLASTand its value is zero, the function returns an empty slice.
Examples
{{ collections.Seq 2 }} → [1 2]
{{ collections.Seq 0 2 }} → [0 1 2]
{{ collections.Seq -2 2 }} → [-2 -1 0 1 2]
{{ collections.Seq -2 2 2 }} → [-2 0 2]Counting down:
{{ collections.Seq -2 }} → [-1 -2]
{{ collections.Seq 3 1 }} → [3 2 1]
{{ collections.Seq 10 -3 1 }} → [10 7 4 1]Iterating over a sequence of integers:
{{ $product := 1 }}
{{ range collections.Seq 4 }}
{{ $product = mul $product . }}
{{ end }}
{{ $product }} → 24Last updated:
November 24, 2026
:
content: Apply style guide to collections functions (04f2e2939)
Improve this page