[Repo Assist] Add AsyncSeq.tryFindBack, findBack, tryFindBackAsync, findBackAsync#289
Closed
github-actions[bot] wants to merge 2 commits intomainfrom
Closed
Conversation
Add four backward-search functions that mirror F# standard library:
- tryFindBack : ('T -> bool) -> AsyncSeq<'T> -> Async<'T option>
- findBack : ('T -> bool) -> AsyncSeq<'T> -> Async<'T>
- tryFindBackAsync : ('T -> Async<bool>) -> AsyncSeq<'T> -> Async<'T option>
- findBackAsync : ('T -> Async<bool>) -> AsyncSeq<'T> -> Async<'T>
These iterate the entire source sequence and return the last element
satisfying the predicate, complementing the existing tryFind / find
(which return the first match). findBack raises KeyNotFoundException
when no element satisfies the predicate; tryFindBack returns None.
All four are documented in AsyncSeq.fsi. 10 new tests added; all
358/358 tests pass.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4 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 PR was created by Repo Assist, an automated AI assistant.
Summary
Adds four backward-search functions that mirror the F# standard library
Seqmodule:tryFindBack('T -> bool) -> AsyncSeq<'T> -> Async<'T option>NonefindBack('T -> bool) -> AsyncSeq<'T> -> Async<'T>KeyNotFoundExceptionon no matchtryFindBackAsync('T -> Async(bool)) -> AsyncSeq<'T> -> Async<'T option>tryFindBackfindBackAsync('T -> Async(bool)) -> AsyncSeq<'T> -> Async<'T>findBackMotivation
AsyncSeqalready hastryFind/find(return the first match). The complementary backward variants — present inSeq.tryFindBack/Seq.findBacksince F# 4.0 — were missing. These are useful for scanning time-ordered sequences or event logs where the most recent matching record is needed.Implementation
tryFindBackAsyncis the primitive: it iterates the entire sequence, overwritingresultwhenever the predicate holds, and returns the final value. The other three functions are simple wrappers.Changes
src/FSharp.Control.AsyncSeq/AsyncSeq.fs— 4 new function implementationssrc/FSharp.Control.AsyncSeq/AsyncSeq.fsi— 4 new public signatures with XML-doctests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs— 10 new testsRELEASE_NOTES.md— added to 4.11.0 entryNew Tests
tryFindBack returns last matching elementSome 6from[1;3;5;2;4;6;7]with even predicatetryFindBack returns None when no element matchesNonetryFindBack returns None for empty sequenceNonetryFindBack returns last element when all matchfindBack returns last matching elementfindBack raises KeyNotFoundException when no matchtryFindBackAsync returns last element satisfying async predicatex < 4→Some 3tryFindBackAsync returns None when nothing matchesx > 99→NonefindBackAsync returns last element satisfying async predicatex % 2 = 0→ last evenfindBackAsync raises KeyNotFoundException when no matchx > 99→ exceptionTest Status
✅ Build succeeded (pre-existing OOM on
netstandard2.1full-solution build — infrastructure limitation, not caused by this change).✅ All 358/358 tests pass (
dotnet test tests/FSharp.Control.AsyncSeq.Tests/...).