Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 1.25 KB

README.md

File metadata and controls

39 lines (30 loc) · 1.25 KB

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

goslices.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 }
goslices.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 }
goslices.Reduce([]int{5, 1, 2, 2}, sum, 0)
// 10

Usage

See DOCUMENTATION for more info.