github.com/searKing/golang/go@v1.2.74/exp/slices/contains.go (about)

     1  // Copyright 2022 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package slices
     6  
     7  import "golang.org/x/exp/slices"
     8  
     9  // Contains reports whether v is present in s.
    10  func Contains[E comparable](s []E, v E) bool {
    11  	return slices.Contains(s, v)
    12  }
    13  
    14  // ContainsFunc reports whether v satisfying f(s[i]) is present in s.
    15  func ContainsFunc[E any](s []E, f func(E) bool) bool {
    16  	return slices.IndexFunc(s, f) >= 0
    17  }