Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/srfrog/slices
Functions that operate on slices. Similar to functions from package strings or package bytes that have been adapted to work with slices.
https://github.com/srfrog/slices
Last synced: 13 days ago
JSON representation
Functions that operate on slices. Similar to functions from package strings or package bytes that have been adapted to work with slices.
- Host: GitHub
- URL: https://github.com/srfrog/slices
- Owner: srfrog
- License: mit
- Created: 2020-07-02T23:17:34.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-11-09T08:18:51.000Z (almost 4 years ago)
- Last Synced: 2024-07-31T20:48:17.884Z (3 months ago)
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 16
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - slices - Functions that operate on slices; like `package strings` but adapted to work with slices. (Data Structures and Algorithms / Miscellaneous Data Structures and Algorithms)
- awesome-go - slices - Functions that operate on slices; like `package strings` but adapted to work with slices. (Data Structures and Algorithms / Miscellaneous Data Structures and Algorithms)
- awesome-go-extra - slices - 07-02T23:17:34Z|2020-11-09T08:18:51Z| (Generators / Miscellaneous Data Structures and Algorithms)
README
# Slices
[![PkgGoDev](https://pkg.go.dev/badge/github.com/srfrog/slices)](https://pkg.go.dev/github.com/srfrog/slices)
[![Go Report Card](https://goreportcard.com/badge/github.com/srfrog/slices?svg=1)](https://goreportcard.com/report/github.com/srfrog/slices)
[![codecov](https://codecov.io/gh/srfrog/slices/branch/master/graph/badge.svg?token=IDUWTIYYZQ)](https://codecov.io/gh/srfrog/slices)
![Build Status](https://github.com/srfrog/slices/workflows/Go/badge.svg)*Functions that operate on slices. Similar to functions from `package strings` or `package bytes` that have been adapted to work with slices.*
## Features
- [x] Using a thin layer of idiomatic Go; correctness over performance.
- [x] Provide most basic slice operations: index, trim, filter, map
- [x] Some PHP favorites like: pop, push, shift, unshift, shuffle, etc...
- [x] Non-destructive returns (won't alter original slice), except for explicit tasks.## Quick Start
Install using "go get":
```bash
go get github.com/srfrog/slices
```Then import from your source:
```
import "github.com/srfrog/slices"
```View [example_test.go][1] for examples of basic usage and features.
## Documentation
The full code documentation is located at GoDoc:
[http://godoc.org/github.com/srfrog/slices](http://godoc.org/github.com/srfrog/slices)
## Usage
This is a en example showing basic usage.
```go
package mainimport(
"fmt""github.com/srfrog/slices"
)func main() {
str := `Don't communicate by sharing memory - share memory by communicating`// Split string by spaces into a slice.
slc := strings.Split(str, " ")// Count the number of "memory" strings in slc.
memories := slices.Count(slc, "memory")
fmt.Println("Memories:", memories)// Split slice into two parts.
parts := slices.Split(slc, "-")
fmt.Println("Split:", parts, len(parts))// Compare second parts slice with original slc.
diff := slices.Diff(slc, parts[1])
fmt.Println("Diff:", diff)// Chunk the slice
chunks := slices.Chunk(parts[0], 1)
fmt.Println("Chunk:", chunks)// Merge the parts
merge := slices.Merge(chunks...)
fmt.Println("Merge:", merge)
}
```[1]: https://github.com/srfrog/slices/blob/master/example_test.go