[Repo Assist] perf: use while! in iter/fold/reduce/mapFold/tryLast/Drop/Truncate#382
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
Conversation
Replace the manual 'go' flag + initial MoveNextAsync pre-advance pattern
with while! in iter, fold, reduce, mapFold, tryLast, and the Drop/Truncate
cases in skipOrTake.
The old pattern:
let! step = e.MoveNextAsync()
go <- step
while go do
...
let! step = e.MoveNextAsync()
go <- step
becomes:
while! e.MoveNextAsync() do
...
This matches the pattern already established by sum, sumBy, average,
averageBy, lengthBy, etc. Benefits:
- Removes one mutable bool (go) per function
- Removes the initial redundant pre-advance call before the loop
- Unifies style across the module
Also simplifies the Drop and Truncate loop bodies to use explicit
i/yielded counters instead of a pos variable with an inline if/else.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
7 tasks
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.
🤖 This is an automated pull request from Repo Assist, an AI assistant.
Summary
This PR replaces the manual
go-flag + initial-MoveNext pre-advance pattern with idiomaticwhile!in six functions:iter,fold,reduce,mapFold,tryLast, and theDrop/Truncatecases ofskipOrTake.The pattern being replaced
Before (in
iter,fold,reduce,mapFold,tryLast):After:
This matches the pattern already established by
sum,sumBy,average,averageBy,lengthBy,lengthBeforeMax, and others.Changes
itergoflag, initial pre-advancewhile! e.MoveNextAsync()per branchfoldgoflag, initial pre-advancewhile! e.MoveNextAsync()per branchreducegoflag, second pre-advance after first-element checkwhile! e.MoveNextAsync()per branchmapFoldgoflag, initial pre-advancewhile! e.MoveNextAsync()per branchtryLastgoflag, initial pre-advancewhile! e.MoveNextAsync()skipOrTake/Dropposcounter with innerif pos < counti < countas loop guard,if contfor restskipOrTake/Truncateposcounter with innerif pos < countyielded < countas loop guardBenefits
goflag)let! step = e.MoveNextAsync(); go <- stepbefore the loopmatch action/folder/...dispatch outside the while loop initerandfold(it was already outside in the original, but the new form makes it clearer that each branch owns its own tight loop)Scope
All changes are purely internal — no public API or behaviour change.
Trade-offs
Test Status
✅ Build: 0 warnings, 0 errors (Release)
✅ Fantomas: formatting check passes
✅ Tests: 5093 passed, 2 skipped, 0 failed