github.com/searKing/golang/go@v1.2.74/container/slice/anymatch.go (about) 1 // Copyright 2020 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 slice 6 7 import ( 8 "github.com/searKing/golang/go/util/object" 9 ) 10 11 // AnyMatchFunc returns whether any elements of this stream match the provided 12 // predicate. May not evaluate the predicate on all elements if not 13 // necessary for determining the result. If the stream is empty then 14 // {@code false} is returned and the predicate is not evaluated. 15 func AnyMatchFunc(s interface{}, f func(interface{}) bool) bool { 16 return anyMatchFunc(Of(s), f, true) 17 } 18 19 // anyMatchFunc is the same as AnyMatchFunc. 20 func anyMatchFunc(s []interface{}, f func(interface{}) bool, truth bool) bool { 21 object.RequireNonNil(s, "anyMatchFunc called on nil slice") 22 object.RequireNonNil(f, "anyMatchFunc called on nil callfn") 23 24 for _, r := range s { 25 if f(r) == truth { 26 return true 27 } 28 } 29 return false 30 }