The goal in mind for this go-slices
module is to provide basic generics to cover all the common operations a developer will typically perform on a slice.
go get github.com/skippyza/go-slices
Filter even numbers
slices.Filter([]int{1, 2, 3, 4, 5}, func(i int) bool { return i%2 == 0 })
// [2 4]
Double all the numbers
double := func(i int) int { return i*2 }
slices.Map([]int{8, 14, 23}, double)
// [16 28 46]
Sum all the numbers in a slice
sum := func(a, b int) int { return a+b }
slices.Reduce([]int{5, 1, 2, 2}, sum, 0)
// 10
See DOCUMENTATION for more info.