https://github.com/skippyza/go-slices
Collection of generic functions for performing common operations of Golang slices
https://github.com/skippyza/go-slices
golang golang-generics golang-lib golang-library golang-slice golang-slices
Last synced: 8 months ago
JSON representation
Collection of generic functions for performing common operations of Golang slices
- Host: GitHub
- URL: https://github.com/skippyza/go-slices
- Owner: SkippyZA
- License: mit
- Created: 2022-11-18T17:24:28.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-09-13T20:33:40.000Z (about 1 year ago)
- Last Synced: 2025-02-12T17:24:04.576Z (9 months ago)
- Topics: golang, golang-generics, golang-lib, golang-library, golang-slice, golang-slices
- Language: Go
- Homepage:
- Size: 42 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://github.com/SkippyZA/go-slices/actions/workflows/lint.yml)
[](https://github.com/SkippyZA/go-slices/actions/workflows/test.yml)
[](https://codecov.io/gh/SkippyZA/go-slices)

# 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
```bash
go get github.com/skippyza/go-slices
```
## Examples
Filter even numbers
```golang
goslices.Filter([]int{1, 2, 3, 4, 5}, func(i int) bool { return i%2 == 0 })
// [2 4]
```
Double all the numbers
```golang
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
```golang
sum := func(a, b int) int { return a+b }
goslices.Reduce([]int{5, 1, 2, 2}, sum, 0)
// 10
```
## Usage
See [DOCUMENTATION](https://pkg.go.dev/github.com/skippyza/go-slices) for more info.