We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 262b870 commit 5d99735Copy full SHA for 5d99735
1 file changed
intra/core/slices.go
@@ -54,6 +54,13 @@ func ShuffleInPlace[T any](c []T) []T {
54
return c
55
}
56
57
+func ChooseOne[T any](c []T) (zz T) {
58
+ if len(c) <= 0 {
59
+ return zz
60
+ }
61
+ return c[rand.Intn(len(c))]
62
+}
63
+
64
// sorts arr x in ascending order. less(a, b) < 0 when a < b, a > 0 when a > b
65
// and 0 when a == b.
66
func Sort[T any](arr []T, less func(a, b T) int) []T {
@@ -107,12 +114,7 @@ func WithoutNils[T any](arr []T) (out []T) {
107
114
108
115
109
116
func IsAny[T any](arr []T, test TestFn[T]) bool {
110
- for _, x := range arr {
111
- if test(x) {
112
- return true
113
- }
- return false
117
+ return slices.ContainsFunc(arr, test)
118
119
120
func IsAll[T any](arr []T, test TestFn[T]) bool {
0 commit comments