aoc24/util/slices.go

22 lines
364 B
Go
Raw Permalink Normal View History

package util
func RemoveFromSlice[T any](s []T, i int) []T {
s[i] = s[len(s)-1]
return s[:len(s)-1]
}
func SliceSwap[T any](s []T, x, y int) {
tmp := s[x]
s[x] = s[y]
s[y] = tmp
}
2024-12-16 21:10:13 +00:00
func SafeGet[T any](s [][]T, at Vec2) T {
var none T
if at.X < 0 || at.Y < 0 || at.Y >= int64(len(s)) || at.X >= int64(len(s[0])) {
return none
}
return s[at.Y][at.X]
}