Skip to content

A fold over an empty sequence answers instead of throwing (#1028) - #1096

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
fix/empty-sequence-folds-1028
Aug 27, 2026
Merged

A fold over an empty sequence answers instead of throwing (#1028)#1096
Rafael-SOWNet merged 1 commit into
masterfrom
fix/empty-sequence-folds-1028

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Collaborator

Closes #1028.

new Entity[0].SumAll();   // AngouriBugException: At least 1 child required
                          // "...please report about it to the official repository"

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.

before now
new Entity[0].SumAll() AngouriBugException 0
new Entity[0].MultiplyAll() AngouriBugException 1
Sumf.Sum(new Entity[0]) AngouriBugException 0
Mulf.Multiply(new Entity[0]) AngouriBugException 1
MathS.Vector() IndexOutOfRangeException InvalidMatrixOperationException
new Entity[0].ToVector() IndexOutOfRangeException InvalidMatrixOperationException

Why 0 and 1 rather than a better exception

A fold over a monoid has an identity. That is not a preference — it is what makes

xs.Concat(ys).SumAll() == xs.SumAll() + ys.SumAll()

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.

IndexOutOfRangeException is a separate problem: it is not under AngouriMathBaseException, so a
caller catching the hierarchy Docs/Usage/Exceptions.md documents 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 >= 1
precondition is genuine. Grepping its callers turned up Sumf.Sum(IReadOnlyList<Entity>) and
Mulf.Multiply(IReadOnlyList<Entity>) doing exactly that — both public, neither mentioned in the
report.

MultiHangBinary itself is unchanged. The issue is right that the bug is at the boundary rather
than 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

`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
Rafael-SOWNet force-pushed the fix/empty-sequence-folds-1028 branch from 82cdf02 to cede6e9 Compare August 27, 2026 18:28
@Rafael-SOWNet
Rafael-SOWNet merged commit 262273b into master Aug 27, 2026
31 checks passed
@Rafael-SOWNet
Rafael-SOWNet deleted the fix/empty-sequence-folds-1028 branch August 27, 2026 18:49
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.

SumAll, MultiplyAll and ToVector throw an internal bug exception on an empty sequence, where ToSet and ToPiecewise answer

1 participant