Standard library / slices

slices.Collect()

Consumes a sequence into a new slice; an empty sequence returns nil. Expected stdout: '[3 1 2]\n'.

Formal Syntax & Structure

go syntaxgo
func Collect[E any](seq iter.Seq[E]) []E

Parameters & Attributes

NameTypeDescription
seqiter.Seq[E]Iterator function producing the input sequence.

Return Value

[]E

Consumes a sequence into a new slice; an empty sequence returns nil.

Working Example

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