github.com/enetx/g@v1.0.80/examples/iter/iter_counter.go (about) 1 package main 2 3 import ( 4 "github.com/enetx/g" 5 "github.com/enetx/g/cmp" 6 ) 7 8 func main() { 9 slice := g.SliceOf(1, 2, 3, 1, 2, 1) 10 11 slice.Iter(). 12 Counter(). 13 SortBy(func(a, b g.Pair[int, g.Int]) cmp.Ordering { return b.Value.Cmp(a.Value) }). 14 Collect(). 15 Print() // MapOrd{1:3, 2:2, 3:1} 16 }