1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-11 08:12:26 +08:00

feat: add Merge function

This commit is contained in:
dudaodong
2022-11-27 20:20:00 +08:00
parent 5722c724e6
commit 7b290989f5
2 changed files with 23 additions and 0 deletions

View File

@@ -618,6 +618,17 @@ func UnionBy[T any, V comparable](predicate func(item T) V, slices ...[]T) []T {
return result
}
// Merge all given slices into one slice
func Merge[T any](slices ...[]T) []T {
result := make([]T, 0)
for _, item := range slices {
result = append(result, item...)
}
return result
}
// Intersection creates a slice of unique values that included by all slices.
func Intersection[T comparable](slices ...[]T) []T {
if len(slices) == 0 {