Standard library / slices
slices.Repeat()
Creates a slice containing count repetitions of the input elements. Panics for negative count or length overflow; result is non-nil. Expected stdout: '[1 2 1 2 1 2]\n'.
Formal Syntax & Structure
go syntaxgo
func Repeat[S ~[]E, E any](x S, count int) SParameters & Attributes
| Name | Type | Description |
|---|---|---|
| x | S | Input value or collection to process. |
| count | int | Number of repetitions. |
Return Value
S
Creates a slice containing count repetitions of the input elements. Panics for negative count or length overflow; result is non-nil.
Working Example
Example Snippetgo
package main
import ( "fmt" "slices")
func main() { fmt.Println(slices.Repeat([]int{1, 2}, 3))}