gitee.com/quant1x/num@v0.3.2/logic_any.go (about)

     1  package num
     2  
     3  import (
     4  	"gitee.com/quant1x/num/x64"
     5  )
     6  
     7  // Any 任意一个为真
     8  func Any[T Number | ~bool](x []T) bool {
     9  	switch vs := any(x).(type) {
    10  	case []bool:
    11  		return x64.Any(vs)
    12  	case []int8:
    13  		return __any_go(vs)
    14  	case []uint8:
    15  		return __any_go(vs)
    16  	case []int16:
    17  		return __any_go(vs)
    18  	case []uint16:
    19  		return __any_go(vs)
    20  	case []int32:
    21  		return __any_go(vs)
    22  	case []uint32:
    23  		return __any_go(vs)
    24  	case []int64:
    25  		return __any_go(vs)
    26  	case []uint64:
    27  		return __any_go(vs)
    28  	case []int:
    29  		return __any_go(vs)
    30  	case []uint:
    31  		return __any_go(vs)
    32  	case []uintptr:
    33  		return __any_go(vs)
    34  	case []float32:
    35  		return __any_go(vs)
    36  	case []float64:
    37  		return __any_go(vs)
    38  	}
    39  	return false
    40  }
    41  
    42  func __any_go[T Number](x []T) bool {
    43  	for i := 0; i < len(x); i++ {
    44  		if x[i] != 0 {
    45  			return true
    46  		}
    47  	}
    48  	return false
    49  }