Skip to content

a series basic set operations for slice type. union, interaction, difference and so on.

License

Notifications You must be signed in to change notification settings

chensanle/sliset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sliset: a series basic set operations for slice type

Doc of Sliset Go Report Card Codecov golang-lint

基于泛型的 slice 伪集合操作,封装常见的 union、interaction 和 difference 等函数。

Installation

Standard go get:

$  go get -v -u github.com/chensanle/sliset

Usage & Example

// 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()

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()

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}

About

a series basic set operations for slice type. union, interaction, difference and so on.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages