sigs.k8s.io/cluster-api-provider-azure@v1.14.3/util/slice/slice.go (about) 1 /* 2 Copyright 2021 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package slice 18 19 import "k8s.io/utils/ptr" 20 21 // Contains tells whether a Contains x. 22 func Contains(a []string, x string) bool { 23 for _, n := range a { 24 if x == n { 25 return true 26 } 27 } 28 return false 29 } 30 31 // ToPtrs takes a slice of values and returns a slice of pointers to the same values. 32 func ToPtrs[T any](in []T) []*T { 33 if in == nil { 34 return nil 35 } 36 ptrs := make([]*T, 0, len(in)) 37 for i := range in { 38 ptrs = append(ptrs, ptr.To(in[i])) 39 } 40 return ptrs 41 }