From 912c0f24dfb83aa62bd0adbe5b17576f042c4125 Mon Sep 17 00:00:00 2001 From: Momchil Atanasov Date: Sun, 3 Mar 2024 18:16:08 +0200 Subject: [PATCH] Delegate to slices.Concat --- slice.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/slice.go b/slice.go index 7e2f56b..650812f 100644 --- a/slice.go +++ b/slice.go @@ -1,6 +1,10 @@ package gog -import "golang.org/x/exp/maps" +import ( + "slices" + + "golang.org/x/exp/maps" +) // Map can be used to transform one slice into another by providing a // function to do the mapping. @@ -150,17 +154,10 @@ func DerefElements[T any](slice []*T) []T { // // This function always allocates a brand new slice with appropriate // capacity and never mutates any of the passed slices. -func Concat[T any](slices ...[]T) []T { - capacity := 0 - for _, slice := range slices { - capacity += len(slice) - } - - result := make([]T, 0, capacity) - for _, slice := range slices { - result = append(result, slice...) - } - return result +// +// Deprecated: Use slices.Concat instead. +func Concat[T any](subSlices ...[]T) []T { + return slices.Concat(subSlices...) } // Merge takes a series of maps and merges them into a single map.