mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
docs: update Last documentation to reflect panic behavior
Document that Last panics on empty slices with a clear error message. Add examples for single element and empty slice cases. Related to Issue 13 (PR #41) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
bcb4dd1e9d
commit
3617c2de8f
13 changed files with 228 additions and 221 deletions
|
|
@ -3,7 +3,7 @@ title: "Last"
|
|||
date: 2022-03-21T13:46:24-04:00
|
||||
---
|
||||
|
||||
`Last` returns the last element of the slice.
|
||||
`Last` returns the last element of the slice. Panics if the slice is empty with a clear error message.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
|
@ -15,7 +15,14 @@ import (
|
|||
|
||||
func main() {
|
||||
nums := []int{1, 9, 2, 8, 3, 7, 4, 6, 5}
|
||||
|
||||
fmt.Println(u.Last(nums)) // 5
|
||||
|
||||
// Single element
|
||||
single := []int{42}
|
||||
fmt.Println(u.Last(single)) // 42
|
||||
|
||||
// Empty slice panics with clear message
|
||||
// empty := []int{}
|
||||
// u.Last(empty) // panic: underscore.Last: empty slice
|
||||
}
|
||||
```
|
||||
|
|
|
|||
Loading…
Reference in a new issue