[Repo Assist] Add AsyncSeq.reduce and AsyncSeq.reduceAsync#242
Merged
Conversation
Adds two new combinators:
- reduce: ('T -> 'T -> 'T) -> AsyncSeq<'T> -> Async<'T>
- reduceAsync: ('T -> 'T -> Async<'T>) -> AsyncSeq<'T> -> Async<'T>
These mirror Seq.reduce: aggregate without an initial state, raising
InvalidOperationException on empty sequences. reduce is implemented
in terms of reduceAsync for consistency.
5 new tests added covering: non-empty sequences, single-element sequences,
empty sequence exception, async reduction, and parity with Seq.reduce.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
Pull request created: #242 |
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 PR was created by Repo Assist, an automated AI assistant.
Summary
Adds two new aggregation combinators that mirror
Seq.reduce:Usage:
Motivation
Seq.reduceis a standard F# function that is commonly used when no natural "zero" element exists (e.g. max, string concatenation, non-commutative operations). Its absence fromAsyncSeqis a minor but consistent API gap.fold/foldAsynccan work around it by passing the first element as the state, but that's awkward and easy to get wrong.Implementation
reduceAsyncconsumes the internal pull-based enumerator directly, yielding the first element as the initial accumulator.reducedelegates toreduceAsync(same pattern asfold/foldAsync).InvalidOperationException("The input sequence was empty.")when the source is empty, matchingSeq.reducesemantics.Test Status
✅ All 199 tests pass (
dotnet test). 5 new tests cover:InvalidOperationExceptionSeq.reduceacross multiple input sizes