Skip to content

Conversation

@FGasper
Copy link
Contributor

@FGasper FGasper commented Feb 6, 2025

This allows code like the following:

foo := []int{1, 2, 3}
lo.Push(&foo, 4)

… 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!

@codecov
Copy link

codecov bot commented Feb 6, 2025

Codecov Report

Attention: Patch coverage is 0% with 44 lines in your changes missing coverage. Please review.

Project coverage is 92.98%. Comparing base (70b763e) to head (27038f3).
Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
slice.go 0.00% 44 Missing ⚠️
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              
Flag Coverage Δ
unittests 92.98% <0.00%> (-1.29%) ⬇️

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.

@samber
Copy link
Owner

samber commented Feb 16, 2025

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 {
Copy link
Owner

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!")
Copy link
Owner

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?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should return bool value which indicates whether it is valid or not.

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.

3 participants