Standard library / slices

slices.Concat()

Concatenates slices into a new slice in argument order; returns nil when total length is zero. Elements are copied shallowly. Expected stdout: '[1 2 3 4]\n'.

Formal Syntax & Structure

go syntaxgo
func Concat[S ~[]E, E any](slices ...S) S

Parameters & Attributes

NameTypeDescription
slices...SSlices to concatenate in argument order.

Return Value

S

Concatenates slices into a new slice in argument order; returns nil when total length is zero. Elements are copied shallowly.

Working Example

Example Snippetgo
package main
import (  "fmt"  "slices")
func main() {  fmt.Println(slices.Concat([]int{1, 2}, []int{3}, []int{4}))}
Go Reference