seq.md (1046B)
1 --- 2 title: seq 3 # linktitle: 4 description: Creates a sequence of integers. 5 date: 2017-02-01 6 publishdate: 2017-02-01 7 lastmod: 2017-02-01 8 categories: [functions] 9 menu: 10 docs: 11 parent: "functions" 12 keywords: [] 13 signature: ["seq LAST", "seq FIRST LAST", "seq FIRST INCREMENT LAST"] 14 workson: [] 15 hugoversion: 16 relatedfuncs: [] 17 deprecated: false 18 draft: false 19 aliases: [] 20 --- 21 22 It's named and used in the model of [GNU's seq][]. 23 24 ``` 25 3 → 1, 2, 3 26 1 2 4 → 1, 3 27 -3 → -1, -2, -3 28 1 4 → 1, 2, 3, 4 29 1 -2 → 1, 0, -1, -2 30 ``` 31 32 ## Example: `seq` with `range` and `after` 33 34 You can use `seq` in combination with `range` and `after`. The following will return 19 elements: 35 36 ``` 37 {{ range after 1 (seq 20)}} 38 {{ end }} 39 ``` 40 41 However, when ranging with an index, the following may be less confusing in that `$indexStartingAt1` and `$num` will return `1,2,3 ... 20`: 42 43 ``` 44 {{ range $index, $num := (seq 20) }} 45 $indexStartingAt1 := (add $index 1) 46 {{ end }} 47 ``` 48 49 50 [GNU's seq]: https://www.gnu.org/software/coreutils/manual/html_node/seq-invocation.html#seq-invocation