An open API service indexing awesome lists of open source software.

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.

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"