diff --git a/last.go b/last.go index d5703a8..a025a08 100644 --- a/last.go +++ b/last.go @@ -1,7 +1,10 @@ package underscore -// Last returns the last element of the slice +// Last returns the last element of the slice. +// Panics if the slice is empty. func Last[T any](values []T) T { - n := len(values) - return values[n-1] + if len(values) == 0 { + panic("underscore.Last: empty slice") + } + return values[len(values)-1] }