Skip to content

Redo the InfiniteSeq module to prefer exceptions to Results#101

Merged
ntwilson merged 5 commits intomainfrom
infinite-seq-redo
Mar 20, 2026
Merged

Redo the InfiniteSeq module to prefer exceptions to Results#101
ntwilson merged 5 commits intomainfrom
infinite-seq-redo

Conversation

@ntwilson
Copy link
Copy Markdown
Owner

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reworks the InfiniteSeq API to treat “hang” scenarios as exceptions (rather than Result/Option), and introduces a reusable Seq.isHungAfter guard to cap evaluation of potentially infinite sequences across the codebase.

Changes:

  • Added InfiniteSequenceEvaluationHung exception and Seq.isHungAfter (plus NonEmpty wrapper) to detect/stop runaway sequence evaluation.
  • Updated InfiniteSeq to be directly iterable (IEnumerable) and added new exception-throwing APIs (item, take, takeWhile, head, uncons, find, etc.), deprecating the previous Result/Option-returning APIs.
  • Updated docs and specs to cover the new APIs and exception behavior.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
SafetyFirst/Seq.fs Adds Seq.isHungAfter; rewrites skipLenient to avoid double enumeration; adds NonEmpty.isHungAfter.
SafetyFirst/InfiniteSeq.fs Refactors InfiniteSeq to be enumerable, adds exception-first APIs, and marks older Result/Option APIs obsolete.
SafetyFirst/ErrorTypes.fs Introduces InfiniteSequenceEvaluationHung exception type.
SafetyFirst.Specs/InfiniteSeqSpec.fs Adds/updates tests for new InfiniteSeq APIs and exception behavior.
ReleaseNotes.md Documents the InfiniteSeq exception-first redesign and new APIs.
README.md Updates InfiniteSeq documentation and references Seq.isHungAfter.
.gitignore Ignores .claude/.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread SafetyFirst/InfiniteSeq.fs Outdated
Comment thread SafetyFirst/InfiniteSeq.fs
Comment on lines +3 to +4
#nowarn "44"

Comment thread README.md Outdated
Comment thread SafetyFirst/InfiniteSeq.fs
Comment thread SafetyFirst/Seq.fs
Comment thread SafetyFirst/Seq.fs
@ntwilson ntwilson requested a review from Copilot March 16, 2026 01:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Reworks the InfiniteSeq API to prefer throwing InfiniteSequenceEvaluationHung over returning Result/Option on hang detection, aligning infinite-sequence “hang” with a bug/crash model rather than a recoverable error.

Changes:

  • Adds Seq.isHungAfter (and Seq.NonEmpty.isHungAfter) as the primary hang-guard mechanism via exceptions.
  • Refactors InfiniteSeq to be directly iterable (IEnumerable) and introduces new APIs (initBounded, initUnbounded, assume, append, plus non-Result versions of item/take/head/etc.), while marking legacy Result/Option APIs obsolete.
  • Updates specs and docs (ReleaseNotes/README) to reflect the new exception-first approach.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
SafetyFirst/Seq.fs Adds Seq.isHungAfter; rewrites skipLenient; adds NonEmpty.isHungAfter.
SafetyFirst/InfiniteSeq.fs Makes InfiniteSeq enumerable; shifts core APIs to throw-on-hang; keeps legacy APIs as [<Obsolete>].
SafetyFirst/ErrorTypes.fs Introduces InfiniteSequenceEvaluationHung : Exception.
SafetyFirst.Specs/SeqSpec.fs Adds unit tests for Seq.isHungAfter.
SafetyFirst.Specs/InfiniteSeqSpec.fs Adds tests for new InfiniteSeq APIs and exception behavior; suppresses obsolete warnings.
ReleaseNotes.md Documents v5.4.0 behavior change and new APIs.
README.md Updates user-facing guidance for InfiniteSeq and Seq.isHungAfter.
.gitignore Ignores .claude/.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +49 to +50
iter.MoveNext() |> ignore
iter.Current) ()
Comment thread SafetyFirst/Seq.fs
Comment on lines +463 to +475
seq {
use e = xs.GetEnumerator()
let mutable remaining = count
let mutable enoughElements = true
while remaining > 0 && enoughElements do
if e.MoveNext() then
remaining <- remaining - 1
else
enoughElements <- false
if enoughElements then
while e.MoveNext() do
yield e.Current
}
 Conflicts:
	ReleaseNotes.md
	SafetyFirst.Specs/SeqSpec.fs
@ntwilson ntwilson merged commit c5ee3f6 into main Mar 20, 2026
1 check passed
@ntwilson ntwilson deleted the infinite-seq-redo branch March 20, 2026 15:45
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.

2 participants