github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xslice/contains.go (about)

     1  package xslice
     2  
     3  import (
     4  	"github.com/go-board/x-go/types"
     5  )
     6  
     7  func Contains(a []interface{}, x interface{}) bool {
     8  	for _, v := range a {
     9  		if v == x {
    10  			return true
    11  		}
    12  	}
    13  	return false
    14  }
    15  
    16  func ContainsComparable(a []types.Comparable, x types.Comparable) bool {
    17  	for _, v := range a {
    18  		if v.Compare(x) == types.OrderingEqual {
    19  			return true
    20  		}
    21  	}
    22  	return false
    23  }
    24  
    25  func ContainsString(a []string, x string) bool {
    26  	for _, v := range a {
    27  		if v == x {
    28  			return true
    29  		}
    30  	}
    31  	return false
    32  }
    33  
    34  func ContainsInt(a []int, x int) bool {
    35  	for _, v := range a {
    36  		if v == x {
    37  			return true
    38  		}
    39  	}
    40  	return false
    41  }
    42  
    43  func ContainsInt64(a []int64, x int64) bool {
    44  	for _, v := range a {
    45  		if v == x {
    46  			return true
    47  		}
    48  	}
    49  	return false
    50  }