-
-
Notifications
You must be signed in to change notification settings - Fork 853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add push, pop, shift, & unshift functions. #588
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #588 +/- ##
==========================================
- Coverage 94.27% 92.98% -1.29%
==========================================
Files 18 18
Lines 3178 3222 +44
==========================================
Hits 2996 2996
- Misses 170 214 +44
Partials 12 12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Please move this work to mutable/ directory. |
// Equivalent to, but more concise than: | ||
// | ||
// collection = append(elements, collection...) | ||
func Unshift[T any, Slice ~[]T](collection *Slice, elements ...T) int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In respect with go semantic, i would replace Push/unshift by Append/Preppend.
|
||
func verifyNonEmpty[T any](slice []T) { | ||
if len(slice) == 0 { | ||
panic("Cannot remove element from empty slice!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like calls to panic in such utilitary lib, any other idea?
This allows code like the following:
… which is a bit more concise than Go’s familiar
foo = append(foo, 4)
idiom.If the maintainers agree that these are good additions, I’ll add tests before merging.
Thanks!