Skip to content

feat: Add NthOr and NthOrEmpty functions#611

Merged
samber merged 2 commits into
samber:masterfrom
edvardsanta:feat/add-nthor-nthempty
Mar 16, 2025
Merged

feat: Add NthOr and NthOrEmpty functions#611
samber merged 2 commits into
samber:masterfrom
edvardsanta:feat/add-nthor-nthempty

Conversation

@edvardsanta

Copy link
Copy Markdown
Contributor

Closes: #602

  • NthOr: Returns the element at the specified index or a provided fallback value if the index is out of bounds.
  • NthOrEmpty: Returns the element at the specified index or the zero value for the slice's element type if the index is out of bounds.

This commit introduces two new functions, `NthOr` and `NthOrEmpty`, to the `find` package. These functions provide a safer way to access elements at a specific index in a slice, handling out-of-bounds scenarios gracefully.

- `NthOr`: Returns the element at the specified index or a provided fallback value if the index is out of bounds.
- `NthOrEmpty`: Returns the element at the specified index or the zero value for the slice's element type if the index is out of bounds.
@codecov

codecov Bot commented Mar 16, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.29%. Comparing base (17d82f4) to head (07449f3).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #611      +/-   ##
==========================================
+ Coverage   94.27%   94.29%   +0.02%     
==========================================
  Files          18       18              
  Lines        3179     3192      +13     
==========================================
+ Hits         2997     3010      +13     
  Misses        170      170              
  Partials       12       12              
Flag Coverage Δ
unittests 94.29% <100.00%> (+0.02%) ⬆️

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.

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.

New slice helpers

2 participants