mirror of
https://github.com/sablierapp/sablier.git
synced 2026-01-03 19:44:59 +01:00
add watch orphans
This commit is contained in:
35
pkg/array/diff.go
Normal file
35
pkg/array/diff.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package array
|
||||
|
||||
type DiffResult[T comparable] struct {
|
||||
Added []T
|
||||
Removed []T
|
||||
}
|
||||
|
||||
func Diff[T comparable](old []T, new []T) DiffResult[T] {
|
||||
oldMap := make(map[T]struct{})
|
||||
newMap := make(map[T]struct{})
|
||||
|
||||
for _, item := range old {
|
||||
oldMap[item] = struct{}{}
|
||||
}
|
||||
|
||||
for _, item := range new {
|
||||
newMap[item] = struct{}{}
|
||||
}
|
||||
|
||||
var result DiffResult[T]
|
||||
|
||||
for item := range newMap {
|
||||
if _, found := oldMap[item]; !found {
|
||||
result.Added = append(result.Added, item)
|
||||
}
|
||||
}
|
||||
|
||||
for item := range oldMap {
|
||||
if _, found := newMap[item]; !found {
|
||||
result.Removed = append(result.Removed, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user