mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
fix: add explicit panic for Last on empty slice (#41)
- 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:
parent
d622c8cba8
commit
2651a3331a
1 changed files with 6 additions and 3 deletions
9
last.go
9
last.go
|
|
@ -1,7 +1,10 @@
|
||||||
package underscore
|
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 {
|
func Last[T any](values []T) T {
|
||||||
n := len(values)
|
if len(values) == 0 {
|
||||||
return values[n-1]
|
panic("underscore.Last: empty slice")
|
||||||
|
}
|
||||||
|
return values[len(values)-1]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue