fix: add explicit panic for Last on empty slice

- Add length check with explicit panic message
- Update documentation to note panic behavior
- Tests already exist and pass

Resolves Issue 13

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Ruidy 2025-11-14 14:46:06 +01:00
parent d622c8cba8
commit e3b85a1419
No known key found for this signature in database
GPG key ID: 705C24D202990805

View file

@ -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]
}