github.com/searKing/golang/go@v1.2.74/container/slice/findany.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  // FindAnyFunc returns an {@link Optional} describing some element of the stream, or an
     8  // empty {@code Optional} if the stream is empty.
     9  func FindAnyFunc(s interface{}, f func(interface{}) bool) interface{} {
    10  	return normalizeElem(findAnyFunc(Of(s), f, true), s)
    11  }
    12  
    13  // findAnyFunc is the same as FindAnyFunc.
    14  func findAnyFunc(s []interface{}, f func(interface{}) bool, truth bool) interface{} {
    15  	idx := findAnyIndexFunc(s, f, truth)
    16  	if idx == -1 {
    17  		return nil
    18  	}
    19  	return s[idx]
    20  }