A fold over an empty sequence answers instead of throwing (#1028) - #1096
Merged
Conversation
`new Entity[0].SumAll()` threw `AngouriBugException`, whose message ends "please report about it to the official repository" -- so an empty list, which a caller's own `Where` can easily produce, asked them to file a bug report against this repository for their own data. A fold over a monoid has an identity: the empty sum is 0 and the empty product is 1. That is not a preference but what makes `xs.Concat(ys).SumAll() == xs.SumAll() + ys.SumAll()` hold for every pair including the empty one, and the test pins that law rather than the two constants. `MathS.Vector()` leaked `IndexOutOfRangeException`, which is not under `AngouriMathBaseException` -- so a caller catching the hierarchy `Docs/Usage/Exceptions.md` documents did not catch it. It refuses with `InvalidMatrixOperationException` now. **Two of the five entry points fixed here are not named in the issue.** The defect is passing an unchecked caller collection into `MultiHangBinary`, whose `>= 1` precondition is genuine; grepping its callers found `Sumf.Sum(IReadOnlyList<Entity>)` and `Mulf.Multiply(IReadOnlyList<Entity>)` doing exactly that, both public. `MultiHangBinary` is unchanged -- the issue is right that the bug is at the boundary, not in the fold. Fails 7 of 7 without the change.
Rafael-SOWNet
force-pushed
the
fix/empty-sequence-folds-1028
branch
from
August 27, 2026 18:28
82cdf02 to
cede6e9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1028.
An empty list — which a caller's own
Wherecan easily produce — asked them to file a bug reportagainst this repository for their own data.
new Entity[0].SumAll()AngouriBugException0new Entity[0].MultiplyAll()AngouriBugException1Sumf.Sum(new Entity[0])AngouriBugException0Mulf.Multiply(new Entity[0])AngouriBugException1MathS.Vector()IndexOutOfRangeExceptionInvalidMatrixOperationExceptionnew Entity[0].ToVector()IndexOutOfRangeExceptionInvalidMatrixOperationExceptionWhy
0and1rather than a better exceptionA fold over a monoid has an identity. That is not a preference — it is what makes
hold for every pair, the empty one included. The test pins that law across every split point
of a 0-, 1- and 3-element sequence rather than pinning the two constants.
IndexOutOfRangeExceptionis a separate problem: it is not underAngouriMathBaseException, so acaller catching the hierarchy
Docs/Usage/Exceptions.mddocuments did not catch it at all.Two of the five entry points are not named in the issue
The defect is passing an unchecked caller collection into
MultiHangBinary, whose>= 1precondition is genuine. Grepping its callers turned up
Sumf.Sum(IReadOnlyList<Entity>)andMulf.Multiply(IReadOnlyList<Entity>)doing exactly that — both public, neither mentioned in thereport.
MultiHangBinaryitself is unchanged. The issue is right that the bug is at the boundary ratherthan in the fold, and its internal callers do rely on the precondition.
Fails 7 of 7 without the change. Full suite: 8758 passed, 0 failed.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Bjumi5K7fg8yx6UK1mZTQd