Conversation
Co-authored-by: hwbrzzl <24771476+hwbrzzl@users.noreply.github.com>
Co-authored-by: hwbrzzl <24771476+hwbrzzl@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1409 +/- ##
==========================================
+ Coverage 66.42% 67.27% +0.85%
==========================================
Files 344 344
Lines 25638 25574 -64
==========================================
+ Hits 17030 17206 +176
+ Misses 7872 7639 -233
+ Partials 736 729 -7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@copilot CI failed |
Investigated CI for this branch at commit c57f84d. There are two failures: (1) Check PR Title is failing because the PR title seen by the workflow is still |
This follow-up addresses high-impact issues from the collection rollout:
LazyCollectionearly-exit paths could leave upstream channel producers blocked, and severalCollectionbehaviors were inconsistent with expected semantics (zip length handling, duplicates, where equality, splice bounds, and where-in ergonomics).LazyCollection: prevent blocked producers on early exits
Every,First,FirstWhere,Some,Take,TakeWhile,ZipdrainChannelhelper to consume remaining items when downstream stops early.Collection behavior alignment and edge-case fixes
Zipnow truncates to the shorter input (no partial trailing pairs).Duplicatesnow returns each duplicated value once.Splicenow treats negativedeleteCountas0.Whereequality/inequality now supports numerically equivalent simple mixed types (e.g.intfield vs numericstringinput).WhereIn/WhereNotInnow accept variadic inputs while preserving compatibility with existing[]interface{}calls.Performance and correctness refinements
Randomnow uses a shared RNG instance (mutex-protected) instead of per-call generator initialization.max/minlocals tomaxVal/minValto avoid built-in name shadowing.MapCollectdoc comment grammar and GoDoc style.Focused coverage additions
WhereIn, numeric string/int equality inWhere, and negativeSplicedeleteCount.Original prompt
This section details on the original issue you should resolve
<issue_title>Collection Library: Address Review Comments and Improvements from PR #1134</issue_title>
<issue_description>## Overview
This issue tracks improvements and fixes needed for the Collection library that was merged in #1134. While the implementation is solid and provides comprehensive Laravel-style collection functionality, several issues were identified during review that should be addressed in follow-up PRs.
Critical Issues
1. Goroutine Leaks in LazyCollection
Files:
support/collect/lazy_collection.goMultiple methods in LazyCollection may leak goroutines by not draining channels after early returns/breaks:
Zip(line 853-859): May leave ch2 goroutine running if ch1 completes firstTake(line 669-676): Breaks early without draining input channelTakeWhile(line 694-700): Similar issue to TakeSome(line 617-621): Returns early without consuming remaining itemsFirst(line 248-251): Returns early without draining channelFirstWhere(line 261-268): Same issueEvery(line 210-218): Same issueFix: Drain channels after early returns to prevent blocking upstream goroutines:
2. Performance Issues
Random() Generator Initialization (line 800)
Unique() and Key Generation Performance (line 1058, 265, 735)
fmt.Sprintf("%v", ...)for key generation which is extremely slow for large structsUnique,Duplicates,Diff,Intersect,GroupBy, and all methods usingseenmapskeyFuncparameter allowing users to provide efficient key extractionBehavioral Issues
3. Zip Inconsistency (line 1239)
Collection.Zip: includes partial pairs when lengths differ →[[1], [2, 3]]for[1,2]and[3]LazyCollection.Zip: stops at shorter collection →[]for same inputs4. Duplicates() Unexpected Behavior (line 272)
[3, 3, 3][3, 3][3](each duplicate value once)5. Where Type Comparison Issues (line 1270)
API Design Issues
6. Pointer Returns (lines 858, 871, 961)
*Tbut it's unclear whyTif needed:Collection[*User]First,Last,Get,Random, etc.(T, bool)pattern or justTwith zero value7. WhereIn/WhereNotIn Usability (line 1172)
[]anyconversion which is cumbersome:...anywhich is easier:...anyinstead of[]any8. Index Parameter Position (line 806)
(item, index), others(index, item)(item, index)everywhere for consistency with Go idioms9. Mutability Inconsistency (line 1052)
Transformmodifies original, others don'tEdge Cases & Bugs
10. Splice Negative deleteCount (line 968)
deleteCountif deleteCount < 0 { deleteCount = 0 }11. Slice Duplicate Check (line 896)
start < 012. Variable Naming Collision (line 613)
max/mincollides with Go built-in functionsmaxVal/minVal13. Debug/Dump Missing Implementation (line 955)
Additional Issues Identified
14. Thread Safety
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.