https://github.com/go-utils/dedupe
Easy Deduplication
https://github.com/go-utils/dedupe
dedup deduplication go golang
Last synced: 8 months ago
JSON representation
Easy Deduplication
- Host: GitHub
- URL: https://github.com/go-utils/dedupe
- Owner: go-utils
- License: mit
- Created: 2020-05-11T04:14:56.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-04-07T00:59:39.000Z (about 4 years ago)
- Last Synced: 2024-11-15T09:52:18.960Z (over 1 year ago)
- Topics: dedup, deduplication, go, golang
- Language: Go
- Homepage:
- Size: 29.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# What is this?
[]int{1, 2, 3, 3}, []string{"1", "2", "3", "3"}, []float64{0.1, 0.2, 0.3, 0.3} etc.
You have to implement each type by yourself when removing duplicates from existing slices.
At that time, I made something that was put together and can be used even a little.
# Installation
```commandline
go get -u github.com/go-utils/dedupe
```
# Usage
```go
import (
"fmt"
"github.com/go-utils/dedupe"
)
func main() {
fmt.Println("[Case1]")
// Basic usage
sliceString := []string{"Go", "V", "C++", "Java", "Python", "Go", "Ruby", "C++", "Go", "V"}
dedupe.Do(&sliceString) // Be sure to pass it by address
fmt.Printf("original slice -> %#v\n\n", sliceString) // change original slice
fmt.Println("[Case2]")
// Extract duplicates without changing the original slice
// But: If it is a structure, you must cast it yourself
sliceFloat64 := []float64{0.1, 0.1, 0.2, 0.2, 0.3, 0.3}
dup := dedupe.NewDeduplication() // or &dedupe.Deduplication{NotChange: true}
dup.Do(&sliceFloat64) // Be sure to pass it by address
if src, err := dup.Float64(); err == nil {
fmt.Printf("extracted slice -> %#v\n", src)
}
fmt.Printf("original slice -> %#v\n", sliceFloat64)
}
```
### Result
```
[Case1]
original slice -> []string{"C++", "Go", "Java", "Python", "Ruby", "V"}
[Case2]
extracted slice -> []float64{0.1, 0.2, 0.3}
original slice -> []float64{0.1, 0.1, 0.2, 0.2, 0.3, 0.3}
```
Check [Go Playground](https://play.golang.org/p/QEUKQciGp4J)
Check [Other patterns](https://github.com/go-utils/dedupe/blob/master/example/main.go)
# Support
`[]bool` `[]float32` `[]float64` `[]int` `[]int64` `[]uint` `[]uint64` `[]string`
`[]struct` `[]*struct` `[]AnyType`
### No Support
`[]func`
# License
MIT