https://github.com/chensanle/sliset
a series basic set operations for slice type. union, interaction, difference and so on.
https://github.com/chensanle/sliset
generic generics golnag interaction set slice
Last synced: about 1 month ago
JSON representation
a series basic set operations for slice type. union, interaction, difference and so on.
- Host: GitHub
- URL: https://github.com/chensanle/sliset
- Owner: chensanle
- License: mit
- Created: 2022-09-04T12:06:11.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-22T02:09:10.000Z (over 1 year ago)
- Last Synced: 2024-06-22T15:06:12.222Z (over 1 year ago)
- Topics: generic, generics, golnag, interaction, set, slice
- Language: Go
- Homepage:
- Size: 28.3 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
sliset: a series basic set operations for slice type
===
[![Doc of Sliset][4]][3]
[![Go Report Card][2]][1]
[![Codecov][6]][5]
[![golang-lint][8]][7]
基于泛型的 slice 伪集合操作,封装常见的 union、interaction 和 difference 等函数。
## Installation
Standard `go get`:
```
$ go get -v -u github.com/chensanle/sliset
```
## Usage & Example
```go
// Difference res = base - compared
func Difference(base, compared []E1) []E1
// Intersection res = base ∩ compared
func Intersection(base, compared []E1) []E1
// Union res = base U compared
func Union(base, compared []E1) []E1
// Uniq remove duplicate elements from the base.
func Uniq(base []E1) []E1
```
### example 1: Difference()
```go
r1 := sliset.Difference([]string{"apple", "fb", "ali"}, []string{"apple"})
fmt.Println("output: ", r1)
// output: []string{"ali"}
r2 := sliset.Difference([]int{1949, 1997, 2008}, []int{2008})
fmt.Println("output: ", r2)
// output: []string{1949, 1997}
```
### example 2: Uniq()
```go
r1 := sliset.Uniq([]string{"apple", "fb", "ali", "apple"})
fmt.Println("output: ", r1)
// output: []string{"apple", "fb", "ali"}
r2 := sliset.Uniq([]int{1949, 1997, 2008, 1949})
fmt.Println("output: ", r2)
// output: []string{1949, 1997, 2008}
```
[1]: "Go Report Card Link"
[2]: "Go Report Card Badge"
[3]: "Doc of Sliset Link"
[4]: "Doc of Sliset Badge"
[5]: "Codecov Link"
[6]: "Codecov Badge"
[7]: "Link"
[8]: "Badge"