Skip to content

Conversation

@rjNemo
Copy link
Owner

@rjNemo rjNemo commented Nov 14, 2025

Summary

  • Add First: returns first element with error handling
  • Add FirstN: returns first n elements safely

Implementation

  • first.go: First and FirstN implementations with proper error handling
  • New ErrEmptySlice error for consistent error handling
  • Comprehensive tests including edge cases (empty, negative n, n > length)
  • Benchmarks included

Testing

go test -v -run "TestFirst"
go test -bench="BenchmarkFirst" -benchmem

All tests pass.

Examples

// First
val, err := First([]int{1,2,3})  // val=1, err=nil
val, err := First([]int{})       // val=0, err=ErrEmptySlice

// FirstN
FirstN([]int{1,2,3,4,5}, 3)   // [1,2,3]
FirstN([]int{1,2,3}, 10)      // [1,2,3]
FirstN([]int{1,2,3}, 0)       // []
FirstN([]int{1,2,3}, -1)      // []

Related

Resolves Issue 16 from ACTION_PLAN.md

🤖 Generated with Claude Code

- Add First: returns first element or error if empty
- Add FirstN: returns first n elements safely
- ErrEmptySlice error for consistent error handling
- Comprehensive tests including edge cases
- Benchmarks included

Resolves Issue 16

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

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Nov 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.21%. Comparing base (d622c8c) to head (8031d77).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #44      +/-   ##
==========================================
+ Coverage   98.63%   99.21%   +0.57%     
==========================================
  Files          39       40       +1     
  Lines         367      382      +15     
==========================================
+ Hits          362      379      +17     
+ Misses          4        2       -2     
  Partials        1        1              
Flag Coverage Δ
unittests 99.21% <100.00%> (+0.57%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rjNemo rjNemo merged commit 5240c27 into main Nov 16, 2025
4 checks passed
@rjNemo rjNemo deleted the feat/issue-16-first-firstn branch November 16, 2025 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants