From ed843e643f9f311fc00808253abb4e829adf7af3 Mon Sep 17 00:00:00 2001 From: Maisem Ali Date: Fri, 3 May 2024 18:42:53 -0700 Subject: [PATCH] types/views: add AppendStrings util func Updates tailscale/corp#19623 Signed-off-by: Maisem Ali --- types/views/views.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/types/views/views.go b/types/views/views.go index 245734961..d58d49db6 100644 --- a/types/views/views.go +++ b/types/views/views.go @@ -9,6 +9,7 @@ "bytes" "encoding/json" "errors" + "fmt" "maps" "slices" @@ -277,6 +278,14 @@ func (v Slice[T]) ContainsFunc(f func(T) bool) bool { return slices.ContainsFunc(v.ж, f) } +// AppendStrings appends the string representation of each element in v to dst. +func AppendStrings[T fmt.Stringer](dst []string, v Slice[T]) []string { + for _, x := range v.ж { + dst = append(dst, x.String()) + } + return dst +} + // SliceContains reports whether v contains element e. // // As it runs in O(n) time, use with care.