Adding Error variants: MapErr, FlatMapErr, ReduceErr...#823
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds error-propagating variants of a large number of collection utility functions in the lo library. When an iteratee/transform/accumulator function can return an error, the *Err variant stops at the first error and returns it immediately, rather than continuing. The PR covers slice.go, map.go, math.go, find.go, and intersect.go, plus corresponding tests and documentation.
Changes:
- Adds
*Errvariants for slice operations:MapErr,FlatMapErr,ReduceErr,ReduceRightErr,UniqByErr,GroupByErr,GroupByMapErr,PartitionByErr,KeyByErr,CountByErr,WithoutByErr - Adds
*Errvariants for map operations:PickByErr,OmitByErr,MapKeysErr,MapValuesErr,MapEntriesErr,MapToSliceErr - Adds
*Errvariants for math/find operations:SumByErr,ProductByErr,MeanByErr,MinByErr,MaxByErr,MinIndexByErr,MaxIndexByErr,EarliestByErr,LatestByErr - Adds comprehensive tests, example functions, and documentation (markdown files + README updates) for all new variants
Reviewed changes
Copilot reviewed 64 out of 64 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| slice.go | Adds 11 new *Err slice utility functions |
| map.go | Adds 6 new *Err map utility functions |
| math.go | Adds SumByErr, ProductByErr, MeanByErr |
| find.go | Adds MinByErr, MaxByErr, MinIndexByErr, MaxIndexByErr, EarliestByErr, LatestByErr |
| intersect.go | Adds WithoutByErr |
| slice_test.go | Tests for all new slice *Err functions |
| map_test.go | Tests for all new map *Err functions (with non-determinism bugs) |
| math_test.go | Tests for SumByErr, ProductByErr, MeanByErr |
| find_test.go | Tests for all new find *Err functions |
| intersect_test.go | Tests for WithoutByErr |
| lo_example_test.go | Example functions for new API |
| README.md | Documentation examples added; contains invalid Go syntax in WithoutByErr example |
| docs/data/core-maperr.md | New doc file with stray trailing text |
| docs/data/core-*.md (others) | New or updated documentation files |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #823 +/- ##
==========================================
+ Coverage 92.11% 92.43% +0.31%
==========================================
Files 32 32
Lines 4259 5007 +748
==========================================
+ Hits 3923 4628 +705
- Misses 252 275 +23
- Partials 84 104 +20
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Really appreciate the work on this! Will a FilterErr variant come in a separate PR? |
|
Nope, it will be added with this PR. 10-15 more helpers are coming in a few minutes ;) |
Full list 👇
from slice.go (13 helpers)
from find.go (8 helpers)
from map.go (7 helpers)
from math.go (3 helpers)
from intersect.go (1 helper)
from tuples.go (3 helpers)
We don't use
errors.Join(...). The helper returns immediately as soon as we get an error.Notes:
mutablesub-package, because it would return a partial result, and I decided to return either a zero value or a full result for the core package. Please tell me what you think.itsub-package because you cannot pass an error in aniter.Seqdata structure. See https://github.com/samber/ro for proper error handling.SumByIandSumByErrI)Fixes #292 #43 #82 #342 #410 #264 #639
Previous participants to the discussion: @Southclaws @NilsJPWerner @finnigantime @wrouesnel @jeremybeard @amitlicht @simek-m @marlon-wiprud @toong-mineis @rostislaved @genvmoroz @wesdotcool @lmika @wangmir @amitlicht @ei-sugimoto @toong-mineis