Merge commit 'f96384a3b596f9bc0a3a035970b09b2c601f0ccb'

This commit is contained in:
Bjørn Erik Pedersen
2023-05-22 16:47:07 +02:00
341 changed files with 3107 additions and 4238 deletions

View File

@@ -1,50 +1,28 @@
---
title: seq
# linktitle:
description: Creates a sequence of integers.
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
description: Returns a slice of integers.
categories: [functions]
menu:
docs:
parent: "functions"
parent: functions
keywords: []
signature: ["seq LAST", "seq FIRST LAST", "seq FIRST INCREMENT LAST"]
workson: []
hugoversion:
relatedfuncs: []
deprecated: false
draft: false
aliases: []
---
It's named and used in the model of [GNU's seq].
```
3 → 1, 2, 3
1 2 41, 3
-3 → -1, -2, -3
1 4 → 1, 2, 3, 4
1 -2 → 1, 0, -1, -2
```go-html-template
{{ seq 2 }} → [1 2]
{{ seq 0 2 }} → [0 1 2]
{{ seq -2 2 }} → [-2 -1 0 1 2]
{{ seq -2 2 2 }}[-2 0 2]
```
## Example: `seq` with `range` and `after`
Iterate over a sequence of integers:
You can use `seq` in combination with `range` and `after`. The following will return 19 elements:
```
{{ range after 1 (seq 20)}}
```go-html-template
{{ $product := 1 }}
{{ range seq 4 }}
{{ $product = mul $product . }}
{{ end }}
{{ $product }} → 24
```
However, when ranging with an index, the following may be less confusing in that `$indexStartingAt1` and `$num` will return `1,2,3 ... 20`:
```
{{ range $index, $num := (seq 20) }}
$indexStartingAt1 := (add $index 1)
{{ end }}
```
[GNU's seq]: https://www.gnu.org/software/coreutils/manual/html_node/seq-invocation.html#seq-invocation