Standard library / slices
slices.Sorted()
Collects an iterator into a new ascending sorted slice; returns nil for an empty sequence. Expected stdout: '[1 2 3]\n'.
Formal Syntax & Structure
go syntaxgo
func Sorted[E cmp.Ordered](seq iter.Seq[E]) []EParameters & Attributes
| Name | Type | Description |
|---|---|---|
| seq | iter.Seq[E] | Iterator function producing the input sequence. |
Return Value
[]E
Collects an iterator into a new ascending sorted slice; returns nil for an empty sequence.
Working Example
Example Snippetgo
package main
import ( "fmt" "slices")
func main() { fmt.Println(slices.Sorted(slices.Values([]int{3, 1, 2})))}