Skip to content

Collection of generic functions for performing common operations of Golang slices

License

Notifications You must be signed in to change notification settings

SkippyZA/go-slices

Repository files navigation

linters test codecov release

go-slices

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.

Installation

go get github.com/skippyza/go-slices

Examples

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

Usage

See DOCUMENTATION for more info.