sugar
is a Golang library that leverages generics to support aggregate & transform functions in Go. It aims to port as many small ultilities from other languages to Go
. The implementation is highly influenced by Python
and JavaScript
.
- Go 1.20
go get github.com/thienhaole92/sugar
- Import the package.
import "github.com/thienhaole92/sugar"
- Call a function. For example:
result := sugar.Map([]int{1, 2, 3, 4}, func(k int) int {
return k - 1
})
fmt.Printf("%v", result)
//output: [0 1 2 3]