We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 64460b5 commit 52b595dCopy full SHA for 52b595d
intra/core/slices.go
@@ -61,6 +61,13 @@ func ChooseOne[T any](c []T) (zz T) {
61
return c[rand.Intn(len(c))]
62
}
63
64
+func FirstOf[T any](c []T) (zz T) {
65
+ if len(c) <= 0 {
66
+ return zz
67
+ }
68
+ return c[0]
69
+}
70
+
71
// sorts arr x in ascending order. less(a, b) < 0 when a < b, a > 0 when a > b
72
// and 0 when a == b.
73
func Sort[T any](arr []T, less func(a, b T) int) []T {
0 commit comments