Skip to content

Commit 52b595d

Browse files
committed
core/slices: peek first ele
1 parent 64460b5 commit 52b595d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

intra/core/slices.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ func ChooseOne[T any](c []T) (zz T) {
6161
return c[rand.Intn(len(c))]
6262
}
6363

64+
func FirstOf[T any](c []T) (zz T) {
65+
if len(c) <= 0 {
66+
return zz
67+
}
68+
return c[0]
69+
}
70+
6471
// sorts arr x in ascending order. less(a, b) < 0 when a < b, a > 0 when a > b
6572
// and 0 when a == b.
6673
func Sort[T any](arr []T, less func(a, b T) int) []T {

0 commit comments

Comments
 (0)