feat: either.Reduce #4
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/reduce_either"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds the function Reduce to the either module that will reduce an either
value in a single value
0e79dacfb0to4aa72f5f984aa72f5f98toddaba1b603AI Code Review
📋 MR Summary
Adds either.Reduce to collapse an Either into a single value and a TestReduce unit test. The implementation returns a function that dispatches to onLeft/onRight based on e.IsLeft(). Tests attempt to cover both Left and Right cases.
Detailed Code Review
The Reduce implementation is straightforward and correctly dispatches to the provided handlers based on IsLeft(). However, there are two classes of issues: (1) the tests contain a loop/iteration bug that will make the test invalid (it ranges incorrectly over a slice and will iterate indices, not elements), and (2) the implementation does not validate that the provided handler functions are non-nil which will cause runtime panics if callers pass nil. Additionally, the test's invocation of Right has inconsistent generics compared to the Left invocation and may not compile depending on the function signature of Right in the codebase. Address the failing test loop first (it prevents running tests), then add defensive checks or document the panicking behavior of Reduce and add tests for that behavior.
📂 File Reviews
📄 `either/either.go` - Introduces Reduce that maps an Either[L,R] to a single T using provided handlers.
📄 `either/either_test.go` - Adds TestReduce to verify Reduce on Left and Right values.
✅ Summary
🤖 AI Code Review | Generated with ai-code-review | Model:
gpt-5-mini⚠️ AI-generated suggestions may be incorrect. Verify before applying. Not a replacement for human review.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.